Skip to content

TypedPython: fill a fresh New's slots by direct release stores (#125) - #371

Merged
b-re-w merged 1 commit into
developfrom
feat/tp-new-fixed-direct
Nov 5, 2026
Merged

b-re-w merged 1 commit into
developfrom
feat/tp-new-fixed-direct

Conversation

@b-re-w

@b-re-w b-re-w commented Nov 5, 2026

Copy link
Copy Markdown
Member

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_fixed stores a new reference straight into each slot of the object it has just allocated (release store), instead of PyMember_SetOne per slot. That is SetOne's own store for a Py_T_OBJECT_EX slot, minus the per-object critical section and the release of the old value (NULL after tp_alloc).
  • Safety argument (header comment and docs/design/typedpython.md 4.3.4): no safepoint between tp_alloc and 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

  • New test_new_fixed_fills_its_fresh_object_with_direct_release_stores: red before (1 failed), green after.
  • test_cgen_classes, test_virtual_objects, test_regions, test_verify_classes, test_free_threaded: 187 passed.
  • Mutant without 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.

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.
@b-re-w
b-re-w merged commit c44a7d9 into develop Nov 5, 2026
5 checks passed
@b-re-w
b-re-w deleted the feat/tp-new-fixed-direct branch November 5, 2026 13:13
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