Repository navigation
TypedPython: fill a fresh New's slots by direct release stores (#125) - #371
Merged
Merged
Conversation
tp_new_fixed no longer goes through PyMember_SetOne for each slot of the object it has just allocated. The store is the one SetOne makes for a Py_T_OBJECT_EX slot (release store of a new reference) without the per-object critical section and the release of the old value, which is NULL after tp_alloc. Nothing between tp_alloc and the last store reaches a safepoint, so no stop-the-world can hand the object to another thread before it is filled. The design note also records why a freelist and later GC tracking were not done.
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.
Part of #125 (the issue stays open: freelist and GC-tracking changes need the owner's decision, see the design note).
What changed
tp_new_fixedstores a new reference straight into each slot of the object it has just allocated (release store), instead ofPyMember_SetOneper slot. That is SetOne's own store for aPy_T_OBJECT_EXslot, minus the per-object critical section and the release of the old value (NULL aftertp_alloc).tp_allocand the last store, so no stop-the-world (gc.get_objects,gc.get_referrers) can hand the object to another thread before it is filled. Slot kind, writability and offset are checked at capture.Tests
test_new_fixed_fills_its_fresh_object_with_direct_release_stores: red before (1 failed), green after.Py_NewRef: test_cgen_classes segfaults (caught).Benchmark (reference only, load 24 to 27): binary-trees
check(make(18))CPU time median 1.08x faster than develop, 9 alternating rounds. Wall-clock runs at load 26 to 65 were unusable. Compiled functions identical to develop: make, check.