Skip to content

spawn Nim compilation - #26061

Draft
arnetheduck wants to merge 13 commits into
nim-lang:develfrom
arnetheduck:spawn-compile
Draft

spawn Nim compilation#26061
arnetheduck wants to merge 13 commits into
nim-lang:develfrom
arnetheduck:spawn-compile

Conversation

@arnetheduck

@arnetheduck arnetheduck commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

When the Nim compiler run, it first loads the AST of the full Nim program into memory (including libraries and the output of compile-time execution / macros) and generates C code there - then, while keeping it all in memory, it calls the C compiler in parallel and finally the linker.

For anything but the smallest applications, this runs the risk of exhausting system memory since the whole program is kept in memory while parallel C compilers are being run - a swap file might turn the OOM into "just" a slow compilation but this is wasteful and not always possible.

Compiling nimbus for example, >10GB of memory is needed which means runners like github actions struggle.

Similarly, attempts could be made to reclaim the memory by deallocating the AST - this is wasted effort in part because deallocating node by node is slow (might require more swapping) and in any case, Nim does not release the memory back to the system so it doesn't buy much.

This PR changes the compilation process to the tried and true model where the Nim->C step is done in a separate process whose resources are released before moving on to the "next" step.

When the Nim compiler runs, it first loads the AST of the full Nim
program into memory and generates C code there - then, while keeping it
all in memory, it calls the C compiler and linker.

For anything but the smallest applications, this runs the risk of
exhausting system memory since the whole program is kept in memory while
parallel C compilers are being run - a swap file might turn the OOM into
"just" a slow compilation but this is wasteful since the swap file must
still be written even though the data in memory is useless by then.

Similarly, attempts could be made to reclaim the memory by deallocating
the AST - this is wasted efort in part because deallocating node by node
is slow (might require swapping in) and in any case, Nim does not
release the memory back to the system meaning that it needs to be
swapped out.

This PR changes the compilation process to the tried and true model
where the Nim->C step is done in a separate process whose resources are
released before moving on to the "next" step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant