spawn Nim compilation - #26061
Draft
arnetheduck wants to merge 13 commits into
Draft
Conversation
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.
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.
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.