Skip to content

Use defining class names for method frames on Python 3.11+ - #463

Open
vzer200 wants to merge 1 commit into
joerick:mainfrom
vzer200:fix/defining-class-frame-names
Open

Use defining class names for method frames on Python 3.11+#463
vzer200 wants to merge 1 commit into
joerick:mainfrom
vzer200:fix/defining-class-frame-names

Conversation

@vzer200

@vzer200 vzer200 commented Sep 8, 2026

Copy link
Copy Markdown

On Python 3.11+, use the code object's static qualified name for a method frame's class label. When two subclasses inherit Event.run, the combined profile now displays Event.run instead of whichever subclass was sampled most often, while retaining the separate overridden apply calls underneath it.

Addresses #340, following the proposed co_qualname approach. Native and Python samplers use the same rule. Static methods, nonstandard receivers, and metaclass methods get their defining class; deleting or reassigning self/cls no longer changes the label. Nested functions and class-body execution do not acquire a class label. Classes defined inside functions retain their full qualified prefix. Frame identity and timing aggregation are unchanged. Python 3.8-3.10 keep their existing dynamic inference.

Validation on Windows x64, using CPython 3.12.14 and 3.10.21 with LLVM-MinGW:

  • Added 27 regression/compatibility cases. Against unchanged 3.12 source, the final changed-test selection gives 25 failures and 3 passes, including the updated existing staticmethod expectation.
  • Full suites: 157 passed / 12 skipped on 3.12; 132 passed / 37 skipped on 3.10. The baseline 3.12 suite passes its original 130 tests. Seven IPython tests pass on each version.
  • An independent automated reviewer reran both full suites and checked 137 frames on 3.12 plus 130 on 3.10 against unchanged source, through both sampler implementations. Final 3.12 names match explicit expectations; frame identifiers and other attributes are preserved. The 3.10 results are unchanged.
  • An independent real Profiler run reproduces the original misleading subclass label and verifies the corrected base-class label with both subclass branches still present.
  • Eight applicable pre-commit checks passed. The JS hook launcher fails identically on baseline and final Windows checkouts; the same bundle-build script invoked through Python passes without generated changes. Existing Trio/IPython environment warnings are reproduced on baseline.

Local getter microbenchmarks showed the native implementation faster in the measured cases and the Python method fallback about 0.08 microseconds per call slower (~13-14%). These are local measurements, not a whole-program performance claim. Other Python versions, operating systems and MSVC were not run locally.

Prepared with Codex and independently reviewed by a separate automated agent before submission. No human review is claimed.

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