-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Optimize unpack, str.__add__ and fastlocals #7293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ef3c5ef
Remove intermediate Vec allocation in unpack_sequence fast path
youknowone b6760e1
Use read-only atomic load before swap in check_signals
youknowone 98ea46e
Cache builtins downcast in ExecutingFrame for LOAD_GLOBAL
youknowone f3a8d8d
Add number Add slot to PyStr for direct str+str dispatch
youknowone 67ed603
Guard FastLocals access in locals() with try_lock on state mutex
youknowone b1cf47c
Use exact type check for builtins_dict cache
youknowone 0af466c
Consolidate with_recursion in _cmp to single guard
youknowone 5b9e078
Add opcode-level fast paths for FOR_ITER, COMPARE_OP, BINARY_OP
youknowone 4c24868
Also check globals is exact dict for LOAD_GLOBAL fast path
youknowone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Guard FastLocals access in locals() with try_lock on state mutex
Address CodeRabbit review: f_locals() could access fastlocals without synchronization when called from another thread. Use try_lock on the state mutex so concurrent access is properly serialized.
- Loading branch information
commit 67ed603466a4ec7f3ce3dcc20143bc7a3b5269ce
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 119
🏁 Script executed:
# Read the frame.rs file to understand the full locals() implementation and FastLocals wc -l crates/vm/src/frame.rsRepository: RustPython/RustPython
Length of output: 92
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 2254
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 352
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1711
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1316
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 4681
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 2144
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1293
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1869
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 3429
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 310
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1117
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 624
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 2883
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 466
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 476
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 936
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 142
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 88
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 857
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 2718
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 144
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 831
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 6123
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 3906
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 2455
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
# Verify that parking_lot mutex's try_lock doesn't distinguish between current thread and other threads web_search parking_lot mutex try_lock same thread behaviorRepository: RustPython/RustPython
Length of output: 115
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 442
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 4828
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1129
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1455
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1147
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
Guard unsafe
fastlocalsreads whentry_lockfails.On line 399,
try_lock()may fail when any thread holds the lock, not just when the current thread holds it. Iftry_lockfails, accessingfastlocalsviaunsafe { self.fastlocals.borrow() }on line 407 violates safety: a different thread executing the frame could be modifying fastlocals concurrently, causing a data race. The assumption that "try_lock failure means same-thread access" lacks runtime verification and contradictsparking_lot::Mutexsemantics.Check
_guardbefore unsafe access and return early if lock acquisition failed.🤖 Prompt for AI Agents