-
Notifications
You must be signed in to change notification settings - Fork 95
Description
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.