Skip to content

[codex] refactor: consolidate interned Python names - #900

Draft
voltjia wants to merge 1 commit into
perf/optimize-generic-tensor-conversionfrom
refactor/consolidate-interned-names
Draft

[codex] refactor: consolidate interned Python names#900
voltjia wants to merge 1 commit into
perf/optimize-generic-tensor-conversionfrom
refactor/consolidate-interned-names

Conversation

@voltjia

@voltjia voltjia commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • replace seven per-name accessors with one function-local InternedNames cache
  • pass the cache by const reference through device and tensor conversion helpers
  • reuse one cache lookup across vector conversions

The cache retains 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
  • fresh focused CPU+NVIDIA builds for both perf: optimize generic tensor conversion #832 head and this commit
  • candidate Add smoke: 6 passed
  • candidate GEMM smoke: 6 passed
  • baseline GEMM smoke: 6 passed

Performance

Baseline: af5d19e254ee14f1a8b7b215354104b56d2877ee (#832 current head)
Candidate: 40beaed0

Both variants were built in fresh virtual environments with the same InfiniRT prefix, CUTLASS checkout, compiler, and focused abs,add,gemm configuration.

Raw cross-process timings on the shared host showed a bimodal CPU P-state (the same conversion path alternated between about 1.53 us and 2.17 us), so those unnormalized timings were not used for the final claim. The causal follow-up used an in-process four-call pybind control with ABBA block order:

  • 10 paired A/B cycles
  • 15 rounds per process
  • 50,000 calls per block
  • physical GPU 1, logical cuda:0
  • CPU affinity fixed to CPU 30
  • 200,000 paired bootstrap resamples, seed 832
  • predeclared non-inferiority margin: +2%
Metric Candidate vs. baseline Paired bootstrap 95% CI
normalized wall time -5.65% [-10.28%, -0.70%]
normalized process CPU time -5.65% [-10.27%, -0.71%]

Both confidence intervals are below the +2% regression margin. The validation-only benchmark binding and result files are not part of this commit.

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