Skip to content

Add --in-process runner mode for environments without subprocess support #233

@ryanking13

Description

@ryanking13

Problem Statement

pyperf currently requires subprocess spawning (subprocess.Popen) for every benchmark run. This makes pyperf unusable in environments where subprocess is not available.

The primary motivating environment is WebAssembly. WebAssembly platform has no subprocess support due to the fundamental platform level limitations of the WebAssembly sandbox. We (Pyodide maintainers) have an interest in running pyperformance benchmarks in WebAssembly to track the Python performance in the browser over time, and also benchmark the recent advancements such as tail call interpreter (pyodide/pyodide#6102).

Proposed Solution

Add a new --in-process flag in the runner that runs the entire benchmark in the current process.

Implementation Plans

I think subclassing the Manager with an InProcessManager that overrides only spawn_worker() to execute WorkerProcessTask.create_run() directly instead of spawning a child process would work

Caveats

In-process mode will not provide the isolation benefits of subprocess:

  • No clean memory state per run
  • No OS-level CPU affinity control
    For environments like Pyodide, this tradeoff is acceptable — subprocess is not an option at all. Results may have slightly different characteristics, but the benchmark values themselves are produced by the exact same timing code path.

Implementation

I am willing to implement this and submit a PR. Feedback on the approach is welcome before I proceed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions