René's URL Explorer Experiment


Title: gh-146640: Optimize int operations by mutating uniquely-referenced operands in place (JIT only) by eendebakpt · Pull Request #146641 · python/cpython · GitHub

Open Graph Title: gh-146640: Optimize int operations by mutating uniquely-referenced operands in place (JIT only) by eendebakpt · Pull Request #146641 · python/cpython

X Title: gh-146640: Optimize int operations by mutating uniquely-referenced operands in place (JIT only) by eendebakpt · Pull Request #146641 · python/cpython

Description: In this PR we add inplace binary operations for int type, similar to #146397. A complication compared to the float case is that the int operations can return small ints which should not be modified in place. In this PR we: Use PyJitRef_MakeUnique(sym_new_compact_int(ctx)); to mark that a symbol is an int that is either unique or one of the small ints. Add _BINARY_OP_ADD_INT_INPLACE (with variations for the other operations) that handles both small ints as input and overflows. An alternative to handling these cases in the opcode would be do deopt. Here we decided not to deopts because this could lead to many deopts. There is a PyStackRef_DUP(TARGET); inside the macro to get the stack effects right. I tried optimizing that, but it requires changing the structure of the opcode following _BINARY_OP_ADD_INT (the POP_TOP ones). I estimate that it is not worth the complexity to try to eliminate that. Micro benchmark results: Pattern main (ns/iter) branch (ns/iter) Speedup Notes total += a*b + c (non-small) 34.4 27.8 1.24x inplace mutation on unique a*b result total += a + b (non-small) 19.8 13.0 1.52x a+b result is unique, inplace on += t = a + b (plain assign) 13.4 14.1 -- no +=, not affected total += a*b + c*d (chain) 40.4 34.6 1.17x two unique products, inplace on + total += a*b + 1 (small int) 23.2 24.1 -- TARGET is small int, fallback to standard All values are non-small integers (> 1024) unless noted. Selected pyperformance benchmarks: ### deltablue ### Mean +- std dev: 1.95 ms +- 0.03 ms -> 1.97 ms +- 0.03 ms: 1.01x slower Not significant ### scimark_fft ### Mean +- std dev: 208 ms +- 5 ms -> 206 ms +- 1 ms: 1.01x faster Not significant ### scimark_lu ### Mean +- std dev: 58.1 ms +- 0.2 ms -> 58.7 ms +- 0.8 ms: 1.01x slower Not significant ### scimark_monte_carlo ### Mean +- std dev: 41.7 ms +- 1.7 ms -> 41.6 ms +- 0.8 ms: 1.00x faster Not significant ### scimark_sor ### Mean +- std dev: 66.8 ms +- 0.6 ms -> 64.3 ms +- 0.5 ms: 1.04x faster Significant (t=26.88) ### scimark_sparse_mat_mult ### Mean +- std dev: 3.64 ms +- 0.03 ms -> 3.64 ms +- 0.04 ms: 1.00x slower Not significant ### spectral_norm ### Mean +- std dev: 56.4 ms +- 0.2 ms -> 51.5 ms +- 0.4 ms: 1.10x faster Significant (t=79.61) Issue: gh-146640

Open Graph Description: In this PR we add inplace binary operations for int type, similar to #146397. A complication compared to the float case is that the int operations can return small ints which should not be modified...

X Description: In this PR we add inplace binary operations for int type, similar to #146397. A complication compared to the float case is that the int operations can return small ints which should not be modified...

Opengraph URL: https://github.com/python/cpython/pull/146641

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:b111d9f4-221b-50a0-0981-343bfc9de936
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE17A:2FD3E:18AACA2:20B439E:6A52C3AC
html-safe-nonce848e3b4ae8909fde7c6630268d16151ecd3bfedd45369b94f7a65d686d34a59f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTdBOjJGRDNFOjE4QUFDQTI6MjBCNDM5RTo2QTUyQzNBQyIsInZpc2l0b3JfaWQiOiIzOTk2ODY1Nzc2ODIwODYzOTE2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacc9c329ba8e3389143c70424be9f661b6bc236723a6ca80603496b1455e63d8fa
hovercard-subject-tagpull_request:3468051163
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/146641/files
twitter:imagehttps://avatars.githubusercontent.com/u/883786?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/883786?s=400&v=4
og:image:altIn this PR we add inplace binary operations for int type, similar to #146397. A complication compared to the float case is that the int operations can return small ints which should not be modified...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/146641/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F146641%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F146641%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/146641/files
Reloadhttps://github.com/python/cpython/pull/146641/files
Reloadhttps://github.com/python/cpython/pull/146641/files
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
Fidget-Spinnerhttps://github.com/Fidget-Spinner
python:mainhttps://github.com/python/cpython/tree/main
eendebakpt:int_int_inplacehttps://github.com/eendebakpt/cpython/tree/int_int_inplace
Conversation 16 https://github.com/python/cpython/pull/146641
Commits 15 https://github.com/python/cpython/pull/146641/commits
Checks 79 https://github.com/python/cpython/pull/146641/checks
Files changed https://github.com/python/cpython/pull/146641/files
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
gh-146640: Optimize int operations by mutating uniquely-referenced operands in place (JIT only) https://github.com/python/cpython/pull/146641/files#top
Show all changes 15 commits https://github.com/python/cpython/pull/146641/files
befeded Add inplace binary operations for type int-int eendebakpt Mar 30, 2026 https://github.com/python/cpython/pull/146641/commits/befeded4197b7aea397168fb20982b7382695c7d
964bb34 rework eendebakpt Mar 30, 2026 https://github.com/python/cpython/pull/146641/commits/964bb34be583a9bd3cf7b97e2d4c97329ee04cc4
f33b452 refactor eendebakpt Mar 30, 2026 https://github.com/python/cpython/pull/146641/commits/f33b4528957ce5de55822c99a10b0cc56ddb27c4
654ae93 fix tag assignment eendebakpt Mar 30, 2026 https://github.com/python/cpython/pull/146641/commits/654ae93b1029536f3574ee8474aade0099461cb9
af5b4c9 fix result refs eendebakpt Mar 30, 2026 https://github.com/python/cpython/pull/146641/commits/af5b4c9eb62316ab5bd2486eec50ca5b8b45e529
9d13a23 review comments eendebakpt Mar 31, 2026 https://github.com/python/cpython/pull/146641/commits/9d13a232f91bb94306e17a149336da79e1610ec3
46b6cca news entry eendebakpt Mar 31, 2026 https://github.com/python/cpython/pull/146641/commits/46b6ccabb8e6fa526abeb1c9373e3becf4f06b8d
63c1317 fix eendebakpt Mar 31, 2026 https://github.com/python/cpython/pull/146641/commits/63c1317c6b8f2c6f1c0c0e00a171fdb2223fe5b2
4d6288b move dup into macro eendebakpt Mar 31, 2026 https://github.com/python/cpython/pull/146641/commits/4d6288bf489abafe7f9239d9ef7443779c21d0b0
73b9a45 Merge branch 'main' into int_int_inplace eendebakpt Mar 31, 2026 https://github.com/python/cpython/pull/146641/commits/73b9a4573b7ec3fa46919af5621a4743b47c812e
3fb1e6c Apply suggestion from @eendebakpt eendebakpt Mar 31, 2026 https://github.com/python/cpython/pull/146641/commits/3fb1e6cbbc311efb268b59b3e3e1a052b95995d8
7710226 revert eendebakpt Mar 31, 2026 https://github.com/python/cpython/pull/146641/commits/7710226e82c354bdef504ccca7937a408a493937
60b81be review comments eendebakpt Apr 1, 2026 https://github.com/python/cpython/pull/146641/commits/60b81be765e8a87c4ea9c68d998dd034b5bdfc29
e0bae62 Merge branch 'main' into int_int_inplace eendebakpt Apr 1, 2026 https://github.com/python/cpython/pull/146641/commits/e0bae62cf3cf9426528dbbe58ba089faf3ca537e
76e0785 Apply suggestion from @eendebakpt eendebakpt Apr 3, 2026 https://github.com/python/cpython/pull/146641/commits/76e07851bd775d4b506e4309994c9cececc00b32
Clear filters https://github.com/python/cpython/pull/146641/files
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
pycore_uop_ids.h https://github.com/python/cpython/pull/146641/files#diff-2a420e4d0d58009249c0f73f7c822167b053bd51cb213b20179bd2aebfc66ff9
pycore_uop_metadata.h https://github.com/python/cpython/pull/146641/files#diff-55e65a72fa31e9b746e03076d2c74b716c0c1171663f36960b2339fcbfae9bab
test_opt.py https://github.com/python/cpython/pull/146641/files#diff-67b5bd915e37f77df79907865982648172c27d3b96fbb072b30a73c6a2735439
2026-03-30-20-00-00.gh-issue-146306.C45609.rst https://github.com/python/cpython/pull/146641/files#diff-ddbb47dcb869b95314a2e440adc1e7d052a6f839504a3ae758c2654894732f3d
bytecodes.c https://github.com/python/cpython/pull/146641/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342
ceval_macros.h https://github.com/python/cpython/pull/146641/files#diff-45baf725df91ed7826458cda8a17c2b4a2e5296504de1ed6a1c5a9ebe6390a47
executor_cases.c.h https://github.com/python/cpython/pull/146641/files#diff-a1c3430c42a66c16e6d2e154491a6da993b187b27c628545a12a02c7b2a06b81
optimizer_bytecodes.c https://github.com/python/cpython/pull/146641/files#diff-e5bd2b14b0b10f0f47786e26306d689ed1361c3dc3b11dcc3ea52b8a2422ff64
optimizer_cases.c.h https://github.com/python/cpython/pull/146641/files#diff-ed4567b3e67709ec57bf4df91ef058cfcbe00d7da11cd2a75e38241fa1ca99d2
Include/internal/pycore_uop_ids.hhttps://github.com/python/cpython/pull/146641/files#diff-2a420e4d0d58009249c0f73f7c822167b053bd51cb213b20179bd2aebfc66ff9
View file https://github.com/eendebakpt/cpython/blob/76e07851bd775d4b506e4309994c9cececc00b32/Include/internal/pycore_uop_ids.h
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
Include/internal/pycore_uop_metadata.hhttps://github.com/python/cpython/pull/146641/files#diff-55e65a72fa31e9b746e03076d2c74b716c0c1171663f36960b2339fcbfae9bab
View file https://github.com/eendebakpt/cpython/blob/76e07851bd775d4b506e4309994c9cececc00b32/Include/internal/pycore_uop_metadata.h
Open in desktop https://desktop.github.com
how customized files appear on GitHubhttps://docs.github.com/github/administering-a-repository/customizing-how-changed-files-appear-on-github
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
Lib/test/test_capi/test_opt.pyhttps://github.com/python/cpython/pull/146641/files#diff-67b5bd915e37f77df79907865982648172c27d3b96fbb072b30a73c6a2735439
View file https://github.com/eendebakpt/cpython/blob/76e07851bd775d4b506e4309994c9cececc00b32/Lib/test/test_capi/test_opt.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/146641/{{ revealButtonHref }}
https://github.com/python/cpython/pull/146641/files#diff-67b5bd915e37f77df79907865982648172c27d3b96fbb072b30a73c6a2735439
https://github.com/python/cpython/pull/146641/files#diff-67b5bd915e37f77df79907865982648172c27d3b96fbb072b30a73c6a2735439
Misc/NEWS.d/next/Core_and_Builtins/2026-03-30-20-00-00.gh-issue-146306.C45609.rsthttps://github.com/python/cpython/pull/146641/files#diff-ddbb47dcb869b95314a2e440adc1e7d052a6f839504a3ae758c2654894732f3d
View file https://github.com/eendebakpt/cpython/blob/76e07851bd775d4b506e4309994c9cececc00b32/Misc/NEWS.d/next/Core_and_Builtins/2026-03-30-20-00-00.gh-issue-146306.C45609.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/146641/{{ revealButtonHref }}
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L225
Python/bytecodes.chttps://github.com/python/cpython/pull/146641/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342
View file https://github.com/eendebakpt/cpython/blob/76e07851bd775d4b506e4309994c9cececc00b32/Python/bytecodes.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/146641/{{ revealButtonHref }}
https://github.com/python/cpython/pull/146641/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342
Fidget-Spinnerhttps://github.com/Fidget-Spinner
Apr 3, 2026https://github.com/python/cpython/pull/146641/files#r3033108593
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
eendebakpthttps://github.com/eendebakpt
Apr 3, 2026https://github.com/python/cpython/pull/146641/files#r3033236675
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
Fidget-Spinnerhttps://github.com/Fidget-Spinner
Apr 3, 2026https://github.com/python/cpython/pull/146641/files#r3033272060
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
https://github.com/python/cpython/pull/146641/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
Please reload this pagehttps://github.com/python/cpython/pull/146641/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.