Repository navigation
Freeze GC objects at exit to skip the Generation 2 sweep - #2062
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
LGTM - I will modify the PR #2061 to remove where this overlaps But in the back of my mind, another thing that might be done is to add a parameter when a Mathics3 session is called, which also has a way of addressing the GC slowness. |
Merged
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.
An alternative to #2061 for the slow exit after loading a large package such as Rubi.
At exit,
Py_Finalize()runs a full cyclic garbage collection that walks the huge Generation 2 graph Rubi leaves behind. This registersgc.freezeas the first atexit handler, so it runs last. Every tracked object moves into the permanent generation, and the final collection has almost nothing to walk.Unlike
os._exit(), the normal shutdown stays intact. The other atexit handlers still run (readline history,--show-statistics, trace dumps),SystemExitstill propagates (Dialog[], embedding hosts), and exit codes are unchanged. Because the hook is onmain()rather than on theQuit[]branch of the REPL loop, it also applies on Ctrl-D.Measurements
Python 3.12.13 on Linux,
Get["Rubi.wl"](2819Intrules), then exit. Time is from the last output to process exit, two runs each:Quit[3]os._exit)Exit code after
Quit[3]is 3 in all variants. Details are in #2061 (comment).test/test_main.pyandtest/test_returncode.pypass locally.🤖 Generated with Claude Code