Repository navigation
Smaller footprint: 16 MB young generation and one isolate - #27
Ivo Horák (horakivo) wants to merge 2 commits into
Conversation
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.
Merging this PR will degrade performance by 32.77%1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
|
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 |
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.Xmnoverrides it).-R:-CompileInIsolates: compile in the main isolate (--vm.XX:+CompileInIsolatesrestores it).On a macOS build the peak RSS of the
memoryrows 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
🤖 Generated with Claude Code