-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-143667: Specialize FOR_ITER for dict.items(), and scalar replace the pair in the JIT #143666
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
base: main
Are you sure you want to change the base?
gh-143667: Specialize FOR_ITER for dict.items(), and scalar replace the pair in the JIT #143666
Conversation
…python into for_iter_dict_items_jit
eendebakpt
left a comment
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.
Nice work! Would the same approach work for enumerate?
Misc/NEWS.d/next/Core_and_Builtins/2026-01-10-21-04-47.gh-issue-143667.MGlHeh.rst
Outdated
Show resolved
Hide resolved
Yes. I'm hesitant to do it for that though. For |
|
@eendebakpt sorry I can't reproduce the speedup on deepcopy anymore. Deepcopy is too unstable on my machine so I have no trust in the results. From what I can see, it's roughly the same speed. |
This PR specializes FOR_ITER for iterating
dct.items(). Furthermore, in the JIT, it goes one step further by avoiding allocation/reuse/extra writes to the pair tuple entirely. Choosing to scalar replace the tuple on the stack instead.According to stats, dict items makes up 33% of specialization failures.
Roughly 33% reduction in execution time for iteration through dictionary items in the JIT on microbenchmark: