gh-148276: Optimize object creation and method calls in the JIT by resolving __init__ at trace optimization time#148277
Open
eendebakpt wants to merge 2 commits intopython:mainfrom
Open
gh-148276: Optimize object creation and method calls in the JIT by resolving __init__ at trace optimization time#148277eendebakpt wants to merge 2 commits intopython:mainfrom
eendebakpt wants to merge 2 commits intopython:mainfrom
Conversation
…nt type guards - _CHECK_AND_ALLOCATE_OBJECT: resolve __init__ from type's _spec_cache so the optimizer can follow into __init__ bodies - _GUARD_TYPE_VERSION_LOCKED: add optimizer handler to track type version and NOP redundant guards on the same object - Add test_guard_type_version_locked_removed Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Fidget-Spinner
left a comment
There was a problem hiding this comment.
LGTM, just two comments on wording.
Comment on lines
+1568
to
+1569
| enabling the optimizer to trace into the init frame and eliminate | ||
| redundant function version and arg count checks. |
Member
There was a problem hiding this comment.
This has nothing to do with tracing into the init frame. We already do that. it's more of propagating information through the frame
| PyHeapTypeObject *cls = (PyHeapTypeObject *)type; | ||
| PyObject *init = FT_ATOMIC_LOAD_PTR_ACQUIRE(cls->_spec_cache.init); | ||
| if (init != NULL && PyFunction_Check(init)) { | ||
| // Record the __init__ function so _CREATE_INIT_FRAME can |
Member
There was a problem hiding this comment.
Suggested change
| // Record the __init__ function so _CREATE_INIT_FRAME can | |
| // Propagate the __init__ function so _CREATE_INIT_FRAME can |
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.
Optimize object creation and method calls in the JIT by resolving
__init__at trace compile time and eliminating redundant type guards. The idea was picked up when experimenting with the ideas in #144388 using Claude Code.Changes
_CHECK_AND_ALLOCATE_OBJECT: resolve the__init__function to a constant via_spec_cache.init, allowing the optimizer to eliminate_CHECK_FUNCTION_VERSIONand_CHECK_FUNCTION_EXACT_ARGSfor the init call_GUARD_TYPE_VERSION_LOCKED: propagate type version info so repeated guards on the same type within a trace are NOPedBenchmark (release JIT, x86_64) on
Point(x, y)p.translate().dist()v.scale().add().dot()Object creation + method chains are 1.2-1.3x faster. Simple method calls and descriptors are unchanged.
Details
<.summary>__init__at trace compile time #148276