Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-134584: Eliminate redundant refcounting from_CALL_TYPE_1#135818

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tomasr8 wants to merge5 commits intopython:main
base:main
Choose a base branch
Loading
fromtomasr8:jit-refcount-call-type

Conversation

tomasr8
Copy link
Member

@tomasr8tomasr8 commentedJun 22, 2025
edited by bedevere-appbot
Loading

Copy link
Member

@Fidget-SpinnerFidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks mostly good, just 2 comments that also explain the CI failure.

@tomasr8
Copy link
MemberAuthor

Thanks for the review! I'll continue working on it tomorrow (Monday) 🙂

Fidget-Spinner reacted with thumbs up emoji

@Fidget-Spinner
Copy link
Member

I just merged#135761 in. Sorry but you'll have to merge the changes in, as I did not ultimately add_SWAP_FAST.

tomasr8 reacted with thumbs up emoji

@tomasr8tomasr8force-pushed thejit-refcount-call-type branch from184d8f1 to85ab405CompareJune 23, 2025 18:19
@tomasr8tomasr8 marked this pull request as ready for reviewJune 23, 2025 18:54
Copy link
Member

@Fidget-SpinnerFidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yay, thank you!

tomasr8 reacted with rocket emoji
@Fidget-Spinner
Copy link
Member

I will do some microbenchmarking to see if this does anything. Give me a sec.

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commentedJun 23, 2025
edited
Loading

On this script:

import pyperfdef func():    x = 1    for _ in range(120000000):        type(x)if __name__ == "__main__":    runner = pyperf.Runner()    runner.bench_func('micro', func)Mean +- std dev: [no-opt] 918 ms +- 17 ms -> [opt] 897 ms +- 21 ms: 1.02x faster

So it's slightly faster. However, note that this optimization won't fully pay off till we get#135465 merged. So let's wait for now till then. Thanks!

Basically right now there's the extra cost of reading and writing to the stack due to the extra _POP_TOP. We're eliminating 1 reference count check in return. This seems to be barely worth it, but I crunched the numbers before and once the stack becomes registers, it becomes very worth it.

If you're interested, I benchmarked my own branch with this (higher is better):

CPython base JIT:Number of long_calcul per second: 10.23 ± 0.13CPython TOS caching:Number of long_calcul per second: 9.60 ± 0.37CPython decref binary op int elimination:Number of long_calcul per second: 10.14 ± 0.07CPython TOS + decref binary op int elimination:Number of long_calcul per second: 11.45 ± 0.10

So we should expect to see an around ~10% speedup once TOS caching is merged, and we start doing this!

@Fidget-Spinner
Copy link
Member

@tomasr8 congrats!!! I decreased the loop count, rebased your PR on top of Mark's TOS caching PR, and did a micro bench with the script above.

TOS Caching vs TOS Caching + This PRMean +- std dev: [no-opt] 210 ms +- 3 ms -> [opt] 195 ms +- 1 ms: 1.08x faster

So 8% improvement if we have TOS caching enabled ontype operations that load a local variable!

tomasr8 reacted with rocket emojitomasr8 reacted with eyes emoji

@tomasr8
Copy link
MemberAuthor

Awesome stuff! And a pretty nice speedup for a relatively simple optimization too!
I can try and have a look at Mark's PR so that we can get it merged sooner :)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Fidget-SpinnerFidget-SpinnerFidget-Spinner approved these changes

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@tomasr8@Fidget-Spinner

[8]ページ先頭

©2009-2025 Movatter.jp