Skip to content

refactor: consolidate interned Python names - #900

Merged
voltjia merged 2 commits into
perf/optimize-generic-tensor-conversionfrom
refactor/consolidate-interned-names
Aug 10, 2026
Merged

refactor: consolidate interned Python names#900
voltjia merged 2 commits into
perf/optimize-generic-tensor-conversionfrom
refactor/consolidate-interned-names

Conversation

@voltjia

@voltjiavoltjia commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • replace seven per-name accessors with one lazily initialized InternedNames instance
  • let device and tensor conversion helpers retrieve the shared instance through GetInternedNames()

InternedNames stores non-owning py::handle fields, 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 --check
  • clang-format 21.1.8 --dry-run --Werror src/pybind11_utils.h
  • focused CPU+NVIDIA build in an isolated environment with pinned InfiniRT and CUTLASS checkouts
  • python -m pytest tests/test_add.py tests/test_gemm.py -m smoke -q -n 1 (12 passed)
  • optimized disassembly confirms that both the const-reference implementation and the final internal-getter implementation execute one steady-state singleton guard in tensor conversion; the compiler folds the nested device-helper lookup

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:0 in the process), and 200,000 session-level paired bootstrap resamples with seed 832. The predeclared non-inferiority margin was +2%.

ComparisonWall time changePaired bootstrap 95% CIProcess CPU time changePaired bootstrap 95% CI
old const-reference implementation (40beaed0) -> final (f05c9e28)-2.44%[-5.44%, +0.63%]-2.46%[-5.45%, +0.60%]
#832 head (af5d19e2) -> final (f05c9e28)-1.48%[-3.77%, +0.59%]-1.46%[-3.76%, +0.61%]

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.

@voltjiavoltjia changed the title [codex] refactor: consolidate interned Python namesrefactor: consolidate interned Python namesAug 10, 2026
@voltjia
voltjia marked this pull request as ready for review August 10, 2026 05:02
@voltjia
voltjia merged commit adc3d77 into perf/optimize-generic-tensor-conversionAug 10, 2026
6 checks passed
@voltjia
voltjia deleted the refactor/consolidate-interned-names branch August 10, 2026 06:46
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>
Sign up for freeto 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.

2 participants

@voltjia@baominghelly