avoid incrementing reference count of function args where possible#5941
Merged
Conversation
Merging this PR will improve performance by ×2.4
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | call_1 |
270 µs | 198.6 µs | +35.96% |
| ⚡ | call_method_1 |
709.4 µs | 300.3 µs | ×2.4 |
| ⚡ | call_method_one_arg |
612.7 µs | 271.5 µs | ×2.3 |
| ⚡ | call_method |
1,268.2 µs | 791.7 µs | +60.19% |
| ⚡ | call |
607.2 µs | 534.8 µs | +13.53% |
Comparing davidhewitt:borrowed-func-args (44c62ab) with main (46d9ca3)
Footnotes
-
1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩
Tpt
reviewed
Apr 3, 2026
Tpt
reviewed
Apr 3, 2026
Tpt
approved these changes
Apr 3, 2026
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.
This is a micro-optimization to avoid temporary reference count cycles in
.callfamily of functions when passed a Rust tuple containing references such as&Py,&Bound, andBorrowedwhere the reference is known to be owned by code somewhere higher up the stack.Benchmarks will show an oversize effect on
call_methodfunctions because I changed these to re-use the method as a Pythonstrrather than passing a Rust&str(which adds a conversion cost).