Conversation
…in gc_free_threading.c comments, NO code changes) (no AI or LLMs were used in discovering the typos or preparing these changes) - Typo fixes for a few items in InternalDocs/garbage_collector.md - At https://github.com/python/cpython/blob/5539c2a5437acc4f4719aabac375368e0d310bd9/InternalDocs/garbage_collector.md?plain=1#L619 "6 GB L2" should be "6 MB L2" (describing AMD Ryzen 5 7600X L2 cache size, see https://web.archive.org/web/20260918004211/https://www.amd.com/en/products/processors/desktops/ryzen/7000-series/amd-ryzen-5-7600x.html for reference) - At https://github.com/python/cpython/blob/5539c2a5437acc4f4719aabac375368e0d310bd9/InternalDocs/garbage_collector.md?plain=1#L451 "<constant number>" should be "constant number" so that it is not hidden in markdown display - At https://github.com/python/cpython/blob/5539c2a5437acc4f4719aabac375368e0d310bd9/InternalDocs/garbage_collector.md?plain=1#L536 "prefech" should be "prefetch" ; I also replaced "LIFO stack, of unlimited size" with "LIFO stack, limited only by available memory" (e.g. https://github.com/python/cpython/blob/a64b7ecba4db5480504a1a83ae6e80c81472fe16/Python/gc_free_threading.c#L1426 , https://github.com/python/cpython/blob/a64b7ecba4db5480504a1a83ae6e80c81472fe16/Python/gc_free_threading.c#L826-L831 , before https://github.com/python/cpython/blob/a64b7ecba4db5480504a1a83ae6e80c81472fe16/Python/gc_free_threading.c#L2116 ) - Typo fixes for 2x "contigous" (in comments, in gc_free_threading.c - NO code/functionality changes): https://github.com/python/cpython/blob/a64b7ecba4db5480504a1a83ae6e80c81472fe16/Python/gc_free_threading.c#L579 and https://github.com/python/cpython/blob/a64b7ecba4db5480504a1a83ae6e80c81472fe16/Python/gc_free_threading.c#L749 - Propose to remove a seemingly outdated (not applicable to e.g. mark alive phase of free-threaded Python builds), potentially confusing paragraph **In the free-threaded build** ( https://peps.python.org/pep-0703/ , https://peps.python.org/pep-0779/ ) already discussed in many places in this article, the "LIFO stack, of unlimited size"[^0] mentioned seems to not use the existing pointers on "the objects themselves"[^5], e.g. in `gc_propagate_alive` (of which it is said "In most programs, this marks nearly all objects that are not actually unreachable"[^1]) `_PyObjectStack_Pop`[^2] and `_PyObjectStack_Push`[^3] are used, and the push seems to allocate fresh memory[^4] https://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Include/internal/pycore_object_stack.h#L37-L48 (for one simple case to consider, in the free threaded build with prefetch disabled, the `gc_propagate_alive` appears to be a DFS of "nearly all objects that are not actually unreachable"[^1] so would seem to have worst case O(n) additional memory requirements -- contrary to "neither does it in any other way require additional memory proportional to the number of objects"[^5]). Thus I propose to remove a paragraph on O(1) space usage, "no additional memory proportional to the number of objects" in its current form as potentially confusing. ( https://github.com/python/cpython/blob/5539c2a5437acc4f4719aabac375368e0d310bd9/InternalDocs/garbage_collector.md?plain=1#L299 ) (it might still be descriptive of some configuration of the non-free threaded GC[^6], to gc.c instead of gc_free_threading.c, only if the doubly linked list pointers used for all traversals in that implementation are built into the objects in advance, _with the caveat that adding overhead to each object, instead of externalizing it to a separate stack, still requires memory proportional to the number of objects_. Note also comments at https://github.com/python/cpython/blob/a64b7ecba4db5480504a1a83ae6e80c81472fe16/Python/gc_free_threading.c#L1192-L1193 , and https://github.com/python/cpython/blob/a64b7ecba4db5480504a1a83ae6e80c81472fe16/Misc/NEWS.d/3.13.0a4.rst?plain=1#L150-L153 ) - Add a note in two places where something is specific to the non-free-threaded build - At https://github.com/python/cpython/blob/41d09220bda74cda6897a4e807d7af0edaff1fd8/InternalDocs/garbage_collector.md?plain=1#L285 note "PREV_MASK_COLLECTING" is the name of the flag used in the non-free-threaded build - At https://github.com/python/cpython/blob/41d09220bda74cda6897a4e807d7af0edaff1fd8/InternalDocs/garbage_collector.md?plain=1#L634 , note the "fat pointer"/"tagged pointer" memory saving techniques applied to the two linked list pointers discussed in that section are specific to the non-free-threaded build References: [^0]: ."LIFO stack, of unlimited size" used during mark alive free threaded build GC phase: https://github.com/python/cpython/blob/5539c2a5437acc4f4719aabac375368e0d310bd9/InternalDocs/garbage_collector.md?plain=1#L536 [^1]: ."nearly all objects that are not actually unreachable" are visited during the mark alive free threaded build GC phase: https://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Python/gc_free_threading.c#L1363 [^2]: ._PyObjectStack_Pop is used by gc_propagate_alive, e.g. at https://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Python/gc_free_threading.c#L1346 ; also after the mark alive stage too at e.g. mark_reachable https://github.com/python/cpython/blob/41d09220bda74cda6897a4e807d7af0edaff1fd8/Python/gc_free_threading.c#L1048 [^3]: ._PyObjectStack_Push is used by gc_propagate_alive, e.g. at https://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Python/gc_free_threading.c#L705 ; also after the mark alive stage too at e.g. visit_clear_unreachable https://github.com/python/cpython/blob/41d09220bda74cda6897a4e807d7af0edaff1fd8/Python/gc_free_threading.c#L1032 . [^4]: . _PyObjectStack_Push seems to allocate fresh memory, not reuse pointers already on the "objects themselves": https://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Include/internal/pycore_object_stack.h#L37-L48 ; and see also `gc_mark_span_push` https://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Python/gc_free_threading.c#L666-L678 [^5]: .vs. "the objects themselves contain all the storage the GC algorithms require" https://github.com/python/cpython/blob/5539c2a5437acc4f4719aabac375368e0d310bd9/InternalDocs/garbage_collector.md?plain=1#L301 (may be true for the non-free threaded build only, for gc.c NOT gc_free_threading.c ; though "neither does it in any other way require additional memory proportional to the number of objects" is still possibly misleading as adding per object overhead still requires memory proportional to the number of objects and is not necessarily more scalable than externalizing that cost to a separate data structure.) [^6]: in other places in the same section distinctions are made between the free threaded and non-free threaded GCs, e.g. at https://github.com/python/cpython/blob/5539c2a5437acc4f4719aabac375368e0d310bd9/InternalDocs/garbage_collector.md?plain=1#L229 but not for this paragraph
…ng.c (no code changes) - gc.c - At https://github.com/python/cpython/blob/f8bbe696f152d302e7eb3eeb0587a1933cae59fc/Python/gc.c#L3 fix "infromation" to "information" - At https://github.com/python/cpython/blob/f8bbe696f152d302e7eb3eeb0587a1933cae59fc/Python/gc.c#L773 fix "suble" to "subtle" - gc_free_threading.c - At https://github.com/python/cpython/blob/f8bbe696f152d302e7eb3eeb0587a1933cae59fc/Python/gc_free_threading.c#L527 fix "intructions" to "instructions"
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.
(no AI or LLMs were used in discovering the typos or preparing these changes)
Typo fixes for a few items in InternalDocs/garbage_collector.md
cpython/InternalDocs/garbage_collector.md
Line 619 in 5539c2a
cpython/InternalDocs/garbage_collector.md
Line 451 in 5539c2a
cpython/InternalDocs/garbage_collector.md
Line 536 in 5539c2a
cpython/Python/gc_free_threading.c
Line 1426 in a64b7ec
cpython/Python/gc_free_threading.c
Lines 826 to 831 in a64b7ec
cpython/Python/gc_free_threading.c
Line 2116 in a64b7ec
Typo fixes for 2x "contigous" (in comments, in gc_free_threading.c - NO code/functionality changes):
cpython/Python/gc_free_threading.c
Line 579 in a64b7ec
cpython/Python/gc_free_threading.c
Line 749 in a64b7ec
Add a note in two places where something is specific to the non-free-threaded build
cpython/InternalDocs/garbage_collector.md
Line 285 in 41d0922
cpython/InternalDocs/garbage_collector.md
Line 634 in 41d0922
Propose to remove a seemingly outdated (not applicable to e.g. mark alive phase of free-threaded Python builds), potentially confusing paragraph
In the free-threaded build ( https://peps.python.org/pep-0703/ , https://peps.python.org/pep-0779/ ) already discussed in many places in this article, the "LIFO stack, of unlimited size"1 mentioned seems to not use the existing pointers on "the objects themselves"2, e.g. in
gc_propagate_alive(of which it is said "In most programs, this marks nearly all objects that are not actually unreachable"3)_PyObjectStack_Pop4 and_PyObjectStack_Push5 are used, and the push seems to allocate fresh memory6cpython/Include/internal/pycore_object_stack.h
Lines 37 to 48 in e2ff498
gc_propagate_aliveappears to be a DFS of "nearly all objects that are not actually unreachable"3 so would seem to have worst case O(n) additional memory requirements -- contrary to "neither does it in any other way require additional memory proportional to the number of objects"2).Thus I propose to remove a paragraph on O(1) space usage, "no additional memory proportional to the number of objects" in its current form as potentially confusing. (
cpython/InternalDocs/garbage_collector.md
Lines 298 to 302 in 5539c2a
(it might still be descriptive of some configuration of the non-free threaded GC7, to gc.c instead of gc_free_threading.c, only if the doubly linked list pointers used for all traversals in that implementation are built into the objects in advance, with the caveat that adding overhead to each object, instead of externalizing it to a separate stack, still requires memory proportional to the number of objects. Note also comments at
cpython/Python/gc_free_threading.c
Lines 1192 to 1193 in a64b7ec
cpython/Misc/NEWS.d/3.13.0a4.rst
Lines 150 to 153 in a64b7ec
References:
Footnotes
."LIFO stack, of unlimited size" used during mark alive free threaded build GC phase: https://github.com/python/cpython/blob/5539c2a5437acc4f4719aabac375368e0d310bd9/InternalDocs/garbage_collector.md?plain=1#L536 ↩
.vs. "the objects themselves contain all the storage the GC algorithms require" https://github.com/python/cpython/blob/5539c2a5437acc4f4719aabac375368e0d310bd9/InternalDocs/garbage_collector.md?plain=1#L301 (may be true for the non-free threaded build only, for gc.c NOT gc_free_threading.c ; though "neither does it in any other way require additional memory proportional to the number of objects" is still possibly misleading as adding per object overhead still requires memory proportional to the number of objects and is not necessarily more scalable than externalizing that cost to a separate data structure.) ↩ ↩2
."nearly all objects that are not actually unreachable" are visited during the mark alive free threaded build GC phase: https://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Python/gc_free_threading.c#L1363 ↩ ↩2
._PyObjectStack_Pop is used by gc_propagate_alive, e.g. at https://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Python/gc_free_threading.c#L1346 ; also after the mark alive stage too at e.g. mark_reachable https://github.com/python/cpython/blob/41d09220bda74cda6897a4e807d7af0edaff1fd8/Python/gc_free_threading.c#L1048 ↩
._PyObjectStack_Push is used by gc_propagate_alive, e.g. at https://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Python/gc_free_threading.c#L705 ; also after the mark alive stage too at e.g. visit_clear_unreachable https://github.com/python/cpython/blob/41d09220bda74cda6897a4e807d7af0edaff1fd8/Python/gc_free_threading.c#L1032 . ↩
. _PyObjectStack_Push seems to allocate fresh memory, not reuse pointers already on the "objects themselves": https://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Include/internal/pycore_object_stack.h#L37-L48 ; and see also
gc_mark_span_pushhttps://github.com/python/cpython/blob/e2ff498cc03886b73fca0429ee745b04646ad8e0/Python/gc_free_threading.c#L666-L678 ↩in other places in the same section distinctions are made between the free threaded and non-free threaded GCs, e.g. at https://github.com/python/cpython/blob/5539c2a5437acc4f4719aabac375368e0d310bd9/InternalDocs/garbage_collector.md?plain=1#L229 but not for this paragraph ↩