Skip to content

Smaller footprint: 16 MB young generation and one isolate - #27

Closed
Ivo Horák (horakivo) wants to merge 2 commits into
developfrom
perf/footprint-no-compiler-isolate
Closed

Ivo Horák (horakivo) wants to merge 2 commits into
developfrom
perf/footprint-no-compiler-isolate

Conversation

@horakivo

Copy link
Copy Markdown
Member

Draft, do not merge. Opened to measure memory and speed on the benchmark host. Contains the single change of the pull request "Compile in the main isolate" plus a cap on the young generation.

Why

Besides the second isolate (see the other pull request), the young generation is large and fully touched: the serial collector starts from a 128 MB heap, which gives a young generation of about 48 MB, and every page of it is written before the first collection and stays resident. When idle the heap holds about 27 MB of which about 3 MB is live; after 12 standard-library imports 71 MB of which about 19 MB is live.

The change

  • -R:MaxNewSize=16777216: young generation capped at 16 MB (--vm.Xmn overrides it).
  • -R:-CompileInIsolates: compile in the main isolate (--vm.XX:+CompileInIsolates restores it).

On a macOS build the peak RSS of the memory rows went from 207 to 143 MB (idle), 259 to 177 MB (imports), 336 to 229 MB (one million instances), 418 to 288 MB (one million dicts) and 320 to 220 MB (one million strings).

Costs to look for in the run

  • A small young generation means more young collections and earlier promotion. An earlier experiment that capped the young generation at 64 MB at run time made the package benchmarks slower, so expect a cost there; the question is how large it is at 16 MB and whether a different size is a better default.
  • The costs of compiling in the main isolate.

🤖 Generated with Claude Code

The serial collector of the native image starts with an initial heap of
128 MB, which gives a young generation of about 48 MB, and lets the young
generation grow to 10% of physical memory. The whole young generation is
touched before the first collection and its pages stay resident, so even
a program that keeps little alive holds tens of MB of garbage pages, on
top of what it keeps.

Build libpythonvm with MaxNewSize=16 MB as the default. More young
collections happen in allocation-heavy code; --vm.Xmn<size> overrides the
default per process.
Truffle compilations of the native standalone run in a separate isolate
by default. That isolate has its own heap, which starts with a young
generation of about 48 MB that is touched before its first collection,
and it maps and touches the image heap a second time. Compile in the
main isolate instead; the compiler's allocations then share the main
heap and its young generation. --vm.XX:+CompileInIsolates restores the
separate isolate per process.
@horakivo Ivo Horák (horakivo) added the perf:bench Runs walltime bench on our infra label Nov 29, 2026
@codspeed

codspeed Bot commented Nov 29, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 32.77%

1 warning

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚡ 8 improved benchmarks
❌ 43 regressed benchmarks
✅ 36 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ packages/orjson-loads[2500] 515.8 ms 4,761.3 ms -89.17%
❌ packages/orjson-roundtrip[2500] 640.4 ms 5,022.2 ms -87.25%
❌ meso/binarytrees3[18] 3.1 s 10.7 s -70.81%
❌ memory/dicts[1000000] 283.5 ms 923.9 ms -69.32%
❌ meso/pads-bipartite-sized[100_000] 936.2 ms 2,742 ms -65.86%
❌ packages/pandas-groupby-merge[150000] 778.5 ms 1,830.5 ms -57.47%
❌ micro-native/c-arith-binop[1000] 4.7 s 10 s -52.87%
❌ meso/raytrace-simple 156.3 ms 324.6 ms -51.86%
❌ memory/objects[1000000] 272.7 ms 549 ms -50.34%
❌ memory/stdlib-imports 251.2 ms 485.1 ms -48.22%
❌ startup/stdlib-imports[3] 784.7 ms 1,487.1 ms -47.23%
❌ memory/strings[1000000] 331.7 ms 602.3 ms -44.93%
❌ packages/pandas-csv[50000] 1.6 s 2.8 s -43.33%
❌ meso/euler31[200] 2.5 s 4.4 s -42.31%
❌ meso/lavaMD_rodinia-sized2[48] 455.9 ms 788.5 ms -42.18%
❌ meso/euler11[10000] 1.2 s 1.9 s -39.74%
❌ meso/bm-float[1000] 486.8 ms 778.3 ms -37.45%
❌ meso/particlefilter_rodinia[2048] 990.7 ms 1,565.5 ms -36.72%
❌ startup/first-run[3] 423.3 ms 664.2 ms -36.27%
❌ packages/lxml-xpath[2500] 1.9 s 2.9 s -35.84%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/footprint-no-compiler-isolate (99c1b80) with develop (55fc469)

Open in CodSpeed

@horakivo

Copy link
Copy Markdown
Member Author

Measured on the benchmark host and rejected: capping the young generation at 16 MB saves memory (idle 169 to 140 MB, after 12 imports 308 to 204 MB, one million dicts 410 to 304 MB) but costs far too much speed. Median iteration time against develop, geometric mean of the ratios: pure Python 1.38, real packages 1.69, C API micro 1.11, interpreter only 1.12, start-up 1.45. Worst rows: binarytrees3 3.2x, pandas-groupby-merge 2.8x, pandas-str 2.7x, orjson-roundtrip 1.95x. The single-isolate half is measured on its own in #26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf:bench Runs walltime bench on our infra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant