Skip to content

Compile in the main isolate in the native standalone - #26

Draft
Ivo Horák (horakivo) wants to merge 1 commit into
developfrom
perf/footprint-one-isolate
Draft

Ivo Horák (horakivo) wants to merge 1 commit into
developfrom
perf/footprint-one-isolate

Conversation

@horakivo

@horakivo Ivo Horák (horakivo) commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Draft, do not merge. Opened to measure memory and speed on the benchmark host.

Why

A fresh graalpy process that does nothing has a peak RSS of about 169 MB on the benchmark host. A breakdown of where that goes (mapping-level bytes on a macOS build, so the structure carries over and the absolute numbers do not) shows that much of it is fixed per process, and that a large part belongs to a second isolate:

  • Truffle compilation runs in a separate compilation isolate by default. It has its own Java heap (about 52 MB touched when idle) and maps the image heap a second time (about 38 MB resident). It exists from the first compilation, which happens during start-up.

The change

Build libpythonvm with -R:-CompileInIsolates, so runtime compilation happens in the main isolate. --vm.XX:+CompileInIsolates restores the default.

On the macOS build the peak RSS of the memory rows went from 207 to 174 MB (idle), 259 to 225 MB (after 12 standard-library imports) and 320 to 276 MB (one million short strings).

Measured

One benchmark run of this branch against develop on the benchmark host (Linux x86-64).

Peak RSS of a fresh process:

Row develop This change
idle 169 MB 144 MB
after 12 standard-library imports 308 MB 232 MB
one million small instances 363 MB 276 MB
one million small dicts 410 MB 347 MB
one million short strings 366 MB 295 MB

Almost every other benchmark's peak RSS also drops by 50 to 90 MB.

Median iteration time, geometric mean of the ratios (above 1 is slower): real packages 1.05, C API micro 1.01, pure Python 1.01, interpreter only 1.00, start-up 1.03, wall time of the memory rows 1.11.

  • Slower: pandas-groupby-merge 0.83 s to 1.07 s, numpy-small-ops 0.63 to 0.70 s up to 0.76 s, lxml-xpath and pandas-apply 12%, c-instantiate-large 0.92 s to 1.22 s, startup/stdlib-imports 8%, the short memory processes 4 to 18%.
  • Pure Python rows move both ways by up to 20% (raytrace-simple, euler11, particlefilter slower; mandelbrot3, knucleotide faster); with one run it is not clear which of these are the build-to-build variation these rows have shown before.

Costs to look for in the run

  • Compiler allocations land in the application's heap, so collections of the application see them.
  • The compiler is no longer isolated: an out-of-memory during a compilation hits the application.

🤖 Generated with Claude Code

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 regress 5 benchmarks

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

⚡ 10 improved benchmarks
❌ 5 regressed benchmarks
✅ 72 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ memory/strings[1000000] 331.7 ms 415.7 ms -20.21%
❌ packages/pandas-groupby-merge[150000] 778.5 ms 972.1 ms -19.92%
❌ meso/pidigits 6.2 s 7.5 s -17.17%
❌ memory/objects[1000000] 272.7 ms 322.5 ms -15.46%
❌ packages/numpy-small-ops[600] 536 ms 618.1 ms -13.29%
⚡ memory/stdlib-imports[peak-rss: 1 ms = 1 MiB] 307.6 ms 231.9 ms +32.62%
⚡ memory/objects[1000000][peak-rss: 1 ms = 1 MiB] 363.2 ms 276.2 ms +31.49%
⚡ memory/strings[1000000][peak-rss: 1 ms = 1 MiB] 366.4 ms 295.1 ms +24.15%
⚡ memory/dicts[1000000][peak-rss: 1 ms = 1 MiB] 409.6 ms 346.9 ms +18.09%
⚡ memory/idle[peak-rss: 1 ms = 1 MiB] 169.1 ms 144.2 ms +17.27%
⚡ micro-native/c-call-method[5000000] 476.5 ms 413.2 ms +15.31%
⚡ meso/pads-bipartite-sized[100_000] 936.2 ms 818.9 ms +14.33%
⚡ packages/pandas-str[20000] 993.3 ms 871.4 ms +13.99%
⚡ micro-native/c-upcall-builtin-function[67108864] 146.5 ms 131.2 ms +11.67%
⚡ meso/knucleotide 1,020.2 ms 920.4 ms +10.84%

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-one-isolate (c240b7b) with develop (55fc469)

Open in CodSpeed

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