refactor: consolidate interned Python names - #900
Merged
voltjia merged 2 commits intoAug 10, 2026
Merged
Conversation
voltjia
marked this pull request as ready for review
August 10, 2026 05:02
baominghelly
approved these changes
Aug 10, 2026
voltjia
merged commit Aug 10, 2026
adc3d77
into
perf/optimize-generic-tensor-conversion
6 checks passed
voltjia
added a commit
that referenced
this pull request
Aug 11, 2026
* perf: optimize generic tensor conversion * refactor: minimize Python C API usage in tensor conversion (#892) * refactor: minimize direct Python C API usage * refactor: clarify integer conversion helper name * test: drop unrelated tensor conversion coverage * refactor: consolidate interned Python names (#900) * refactor: consolidate interned Python names * refactor: simplify interned name access * refactor: rename vector conversion helper --------- Co-authored-by: Jiacheng Huang <45955067+voltjia@users.noreply.github.com>
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.
Summary
InternedNamesinstanceGetInternedNames()InternedNamesstores non-owningpy::handlefields, so the intentionally retained interned-name references are not decref'd during static destruction.GetInternedNames()keeps Python C API initialization deferred until a conversion runs with an active interpreter.Validation
git diff --checkclang-format 21.1.8 --dry-run --Werror src/pybind11_utils.hpython -m pytest tests/test_add.py tests/test_gemm.py -m smoke -q -n 1(12 passed)Performance
The focused tensor-conversion benchmark used persistent variant workers to exclude interpreter startup from timed regions. Each comparison used 10 independent paired sessions, 15 rounds per session, 50,000 calls per block, alternating B/C/C/B block order, CPU 30 affinity, physical GPU 1 (
cuda:0in the process), and 200,000 session-level paired bootstrap resamples with seed 832. The predeclared non-inferiority margin was +2%.40beaed0) -> final (f05c9e28)af5d19e2) -> final (f05c9e28)All confidence-interval upper bounds are below the +2% regression margin. The point estimates are favorable, but the intervals include zero, so the result is stated as non-inferiority rather than a speedup. The validation-only benchmark binding, harness, and raw results are not part of this PR.