Measure what a sub-interpreter cell actually costs - #292
Merged
Merged
Conversation
The performance snapshot quoted 0.7 ms spawn and 0.5 MiB RSS against the "sub-interpreter backend". Those are numbers for the thread backend that `backend="subinterpreter"` selects today, not for a CPython sub-interpreter, so they understate the roadmap item that replaces it by more than an order of magnitude. Two of the four rows were also not produced by anything in the repository. Add scripts/cell_cost.py, which measures the primitives that backend would be built on, and quote it. On free-threaded CPython 3.14 a cell costs 10.9 ms and 3.5 MiB bare, 56.8 ms and 13.3 MiB once it has imported a realistic module surface -- against 1.62 ms for a fork(), which is a real boundary. The one regime where a cell is cheap is dispatch onto an already-warm pooled interpreter, at 0.82 ms, which is an argument for a cell pool rather than an interpreter per request. The script also separates two things that get conflated: on the free-threaded build four plain threads scaled 3.3x against four cells' 3.9x, while on a GIL build the same threads scaled 0.96x. Parallelism comes from the build; sub-interpreters buy a private sys.modules and a private set of globals. Lifecycle measurement is gated to CPython 3.14+. Holding ~20 interpreters that imported http.client or email.message and then destroying them aborts the process with `munmap_chunk(): invalid pointer` on 3.13's private `_interpreters`; the same workload is clean on 3.14's public `concurrent.interpreters`. `--allow-unstable-api` measures anyway. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fs1hTtmF4Hm9h617AG9Gse
This was referenced Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First of a series of independent PRs working toward an honest multi-tenant Python execution fabric on free-threaded CPython. This one fixes the performance claims and adds the harness that produces them.
The problem
The performance snapshot quoted these against "the sub-interpreter backend":
Two problems. The first two rows are numbers for the thread backend that
backend="subinterpreter"selects today — not for a CPython sub-interpreter — so they understate the roadmap item that replaces it by more than an order of magnitude. The last two rows are not produced by anything in the repository.What this adds
scripts/cell_cost.pymeasures the CPython primitives the planned sub-interpreter backend would be built on, so the roadmap can be argued from numbers taken on a real machine. Measured here on free-threaded CPython 3.14, 4-core container,--iterations 30:x = 1)json, re, dataclasses+ email, http.client, logging, argparsefork()of a warm parentThree things follow, and they shape the rest of the series:
fork(), which is a real boundary, costs less than the cheapest possible cell.sys.modulesand a private set of globals per tenant on a free-threaded one.A CPython bug worth knowing about
The lifecycle rows are gated to CPython 3.14+. Holding ~20 interpreters that have imported
http.clientoremail.messageand then destroying them aborts the process:Reproducible on 3.13.12's private
_interpreters; clean on 3.14's publicconcurrent.interpreterswith the same workload.--allow-unstable-apimeasures anyway. This is a direct argument for targeting 3.14+ rather than the private module when the real backend lands.Scope
Docs and a new script only — no runtime behaviour changes. The README's shipped-backend numbers are kept and relabelled as thread-backend figures; the two unreproducible rows are dropped rather than left standing.
Testing
tests/test_cell_cost.py— 6 new tests covering the reporting contract the README quotes from and the version guard (the guard is asserted via monkeypatch so it is checked on every Python in the matrix, not just 3.13).test_apply_confinement_installs_seccomp_and_allows_normal_syscalls, is pre-existing and environmental — seccomp is unavailable here — and reproduces on unmodifiedmain.pre-commit run --all-files: isort, black, pylint, flake8, mypy all pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01Fs1hTtmF4Hm9h617AG9Gse
Generated by Claude Code