René's URL Explorer Experiment


Title: `TO_BOOL_INT` repeatedly misses for non-compact exact integers · Issue #155486 · python/cpython · GitHub

Open Graph Title: `TO_BOOL_INT` repeatedly misses for non-compact exact integers · Issue #155486 · python/cpython

X Title: `TO_BOOL_INT` repeatedly misses for non-compact exact integers · Issue #155486 · python/cpython

Description: Feature or enhancement Proposal: Versions CPython 3.15.0b4, Ubuntu 24.04.4 LTS, gcc 13.3.0 Enhancement I noticed that the specialization function for TO_BOOL and the guard used by TO_BOOL_INT accept different sets of integers. _Py_Specia...

Open Graph Description: Feature or enhancement Proposal: Versions CPython 3.15.0b4, Ubuntu 24.04.4 LTS, gcc 13.3.0 Enhancement I noticed that the specialization function for TO_BOOL and the guard used by TO_BOOL_INT accep...

X Description: Feature or enhancement Proposal: Versions CPython 3.15.0b4, Ubuntu 24.04.4 LTS, gcc 13.3.0 Enhancement I noticed that the specialization function for TO_BOOL and the guard used by TO_BOOL_INT accep...

Opengraph URL: https://github.com/python/cpython/issues/155486

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`TO_BOOL_INT` repeatedly misses for non-compact exact integers","articleBody":"# Feature or enhancement\n\n### Proposal:\n\n## Versions\n\nCPython 3.15.0b4, Ubuntu 24.04.4 LTS, gcc 13.3.0\n\n## Enhancement\n\nI noticed that the specialization function for `TO_BOOL` and the guard used by `TO_BOOL_INT` accept different sets of integers.\n\n[`_Py_Specialize_ToBool()`](https://github.com/python/cpython/blob/1d90627f1660253b30e5efc2ca092a6231737993/Python/specialize.c#L2842-L2855) selects `TO_BOOL_INT` for any exact integer:\n\n```\nif (PyLong_CheckExact(value)) {\n    specialized_op = TO_BOOL_INT;\n    goto success;\n}\n```\n\nHowever, the [`TO_BOOL_INT` macro](https://github.com/python/cpython/blob/1d90627f1660253b30e5efc2ca092a6231737993/Python/bytecodes.c#L520-L529) uses `_GUARD_TOS_INT`, and that requires the integer to be compact:\n\n```\nop(_GUARD_TOS_INT, (value -- value)) {\n    PyObject *value_o = PyStackRef_AsPyObjectBorrow(value);\n    EXIT_IF(!_PyLong_CheckExactAndCompact(value_o));\n}\n```\n\nAs a result, a **non-compact exact integer** can cause `TO_BOOL_INT` to be selected and then immediately miss its guard. \n\nThis mismatch appears to have been introduced by [GH-143759](https://github.com/python/cpython/pull/143759). Before the refactoring, [`TO_BOOL_INT`](https://github.com/python/cpython/blob/66e1399311c17684c6e26f5d9d9603fbd0717d0d/Python/bytecodes.c#L491-L504) had its own `PyLong_CheckExact()` guard. The refactoring replaced it with a macro using the shared `_GUARD_TOS_INT`, whose domain is narrower.\n\nI see two alternative ways to fix this.\n\n## Option 1: narrow the specialization function\n\nOne option would be to change the integer check in `_Py_Specialize_ToBool()` so that it agrees with the existing guard:\n\n```\nif (_PyLong_CheckExactAndCompact(value)) {\n    specialized_op = TO_BOOL_INT;\n    goto success;\n}\n```\n\nWith this change, non-compact integers remain on the generic `TO_BOOL` path instead of repeatedly entering and missing `TO_BOOL_INT`.\n\nMy main concern with this option was whether the additional compactness check in the specialization function could regress the common case (compact int), so I benchmarked both compact and non-compact integers.\n\nThe benchmark target contained 100 `TO_BOOL` sites and was warmed up before each measurement:\n\n```\nstart = time.perf_counter_ns()\nfor _ in range(10_000):\n    target(value)\nelapsed = time.perf_counter_ns() - start\n```\n\nPositive values mean that the patched build was faster:\n\n| Version      | Input                 | Performance change                    |\n| ------------ | --------------------- | ------------------------------------- |\n| CPython 3.15 | non-compact exact int | +2.21% (95% CI: +1.64% to +2.86%) |\n| CPython 3.15 | compact exact int     | +0.31% (95% CI: −0.15% to +0.70%)     |\n| CPython main | non-compact exact int | +4.03% (95% CI: +1.43% to +7.10%) |\n| CPython main | compact exact int     | −0.23% (95% CI: −0.50% to +0.07%)     |\n\nThe non-compact case improved because it no longer repeatedly enters and misses `TO_BOOL_INT`. For compact integers, both confidence intervals include zero, so I did not find evidence that the stronger specialization check causes a regression.\n\n## Option 2: give `TO_BOOL_INT` an exact-int guard\n\nThe other option is to keep `_Py_Specialize_ToBool()` unchanged and add a guard that checks exact type without requiring compactness:\n\n```\nop(_GUARD_TOS_EXACT_INT, (value -- value)) {\n    PyObject *value_o = PyStackRef_AsPyObjectBorrow(value);\n    EXIT_IF(!PyLong_CheckExact(value_o));\n}\n```\n\nThe `TO_BOOL_INT` macro would then use the new guard:\n\n```\nmacro(TO_BOOL_INT) =\n    _GUARD_TOS_EXACT_INT +\n    unused/1 +\n    unused/2 +\n    _TO_BOOL_INT +\n    _POP_TOP_INT;\n```\n\nThis would restore the specialization domain from before GH-143759.\n\n---\n\nI am not sure which of these two options is preferable, but the current mismatch seems worth fixing, so I am opening this issue to get feedback on which direction would be better.\n\n### Has this already been discussed elsewhere?\n\nNo response given\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-155531\n* gh-155699\n* gh-155700\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/marinelay","@type":"Person","name":"marinelay"},"datePublished":"2026-08-10T12:45:58Z","url":"https://github.com/python/cpython/issues/155486"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:8ccf59bb-cec0-de32-19fe-cb4644c0c171
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC4F8:36534B:32B0E5:46B16F:6AECB8B4
html-safe-nonce1aa19251f9b523f7042d4b9ad3933d80ed5b71d1ab8d9d73a79df8bb4ecd68f8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNEY4OjM2NTM0QjozMkIwRTU6NDZCMTZGOjZBRUNCOEI0IiwidmlzaXRvcl9pZCI6IjY3ODQ0MDQ2NTQwNzk2NTQwNjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac1df2b3af1dd009fc9a9d8e5aa51d32d985145dccf152d067edef09748985fafb
hovercard-subject-tagissue:5110220257
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/155486/issue_layout
twitter:imagehttps://opengraph.githubassets.com/8c084d1fad0e517192fdb789ab4a52e796307a4b6c52e35c40f05ba927ccb2da/python/cpython/issues/155486
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/8c084d1fad0e517192fdb789ab4a52e796307a4b6c52e35c40f05ba927ccb2da/python/cpython/issues/155486
og:image:altFeature or enhancement Proposal: Versions CPython 3.15.0b4, Ubuntu 24.04.4 LTS, gcc 13.3.0 Enhancement I noticed that the specialization function for TO_BOOL and the guard used by TO_BOOL_INT accep...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemarinelay
hostnamegithub.com
expected-hostnamegithub.com
None95ae5445dec4cded2bc4f9d97ede92b9116c0bf381a08a5c844b60b5bddcbc97
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasedb4ef601a7f034ae2a68e17d6eeaeb7ee9470192
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/155486#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F155486
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F155486
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/155486
Reloadhttps://github.com/python/cpython/issues/155486
Reloadhttps://github.com/python/cpython/issues/155486
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.3k (2.3k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/pulse
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/155486
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/155486
TO_BOOL_INT repeatedly misses for non-compact exact integershttps://github.com/python/cpython/issues/155486#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/marinelay
marinelayhttps://github.com/marinelay
on Aug 10, 2026https://github.com/python/cpython/issues/155486#issue-5110220257
_Py_Specialize_ToBool()https://github.com/python/cpython/blob/1d90627f1660253b30e5efc2ca092a6231737993/Python/specialize.c#L2842-L2855
TO_BOOL_INT macrohttps://github.com/python/cpython/blob/1d90627f1660253b30e5efc2ca092a6231737993/Python/bytecodes.c#L520-L529
GH-143759https://github.com/python/cpython/pull/143759
TO_BOOL_INThttps://github.com/python/cpython/blob/66e1399311c17684c6e26f5d9d9603fbd0717d0d/Python/bytecodes.c#L491-L504
GH-143759https://github.com/python/cpython/pull/143759
gh-155486: Allow non-compact integers in TO_BOOL_INT #155531https://github.com/python/cpython/pull/155531
[3.15] gh-155486: Allow non-compact integers in TO_BOOL_INT (GH-155531) #155699https://github.com/python/cpython/pull/155699
[3.15] gh-155486: Allow non-compact integers in TO_BOOL_INT (GH-155531) #155700https://github.com/python/cpython/pull/155700
marinelayhttps://github.com/marinelay
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
on Aug 10, 2026https://github.com/python/cpython/issues/155486#event-29222552327
https://github.com/corona10
corona10https://github.com/corona10
on Aug 10, 2026https://github.com/python/cpython/issues/155486#issuecomment-5242719239
@Fidget-Spinnerhttps://github.com/Fidget-Spinner
https://github.com/Fidget-Spinner
Fidget-Spinnerhttps://github.com/Fidget-Spinner
on Aug 10, 2026https://github.com/python/cpython/issues/155486#issuecomment-5242888032
https://github.com/corona10
corona10https://github.com/corona10
on Aug 10, 2026https://github.com/python/cpython/issues/155486#issuecomment-5242923658
@marinelayhttps://github.com/marinelay
StanFromIrelandhttps://github.com/StanFromIreland
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Aug 10, 2026https://github.com/python/cpython/issues/155486#event-29244327025
marinelayhttps://github.com/marinelay
on Aug 12, 2026https://github.com/python/cpython/issues/155486#event-29322921864
pythongh-155486: optimize exact integer guard in JIThttps://github.com/marinelay/cpython/commit/5e5024acc21ea2567c8adafd081685305642ff1c
pythongh-155486https://github.com/python/cpython/issues/155486
5e5024ahttps://github.com/marinelay/cpython/commit/5e5024acc21ea2567c8adafd081685305642ff1c
pythongh-155486: Add test for TO_BOOL_INT guard eliminationhttps://github.com/marinelay/cpython/commit/88c88717d868dd2f8ebed9c886d64459acb7ccba
pythongh-155486https://github.com/python/cpython/issues/155486
88c8871https://github.com/marinelay/cpython/commit/88c88717d868dd2f8ebed9c886d64459acb7ccba
pythongh-155486: merge test cases for TO_BOOL_INThttps://github.com/marinelay/cpython/commit/3a15dddb3ca007a35195272771d0c53304c9b783
pythongh-155486https://github.com/python/cpython/issues/155486
3a15dddhttps://github.com/marinelay/cpython/commit/3a15dddb3ca007a35195272771d0c53304c9b783
Fidget-Spinnerhttps://github.com/Fidget-Spinner
on Aug 13, 2026https://github.com/python/cpython/issues/155486#event-29396710120
gh-155486: Allow non-compact integers in `TO_BOOL_INT` (GH-155531)https://github.com/python/cpython/commit/cd98657f0a8767e44c1db40dadedb5e278f7bdac
gh-155486https://github.com/python/cpython/issues/155486
GH-155531https://github.com/python/cpython/pull/155531
cd98657https://github.com/python/cpython/commit/cd98657f0a8767e44c1db40dadedb5e278f7bdac
Fidget-Spinnerhttps://github.com/Fidget-Spinner
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
on Aug 13, 2026https://github.com/python/cpython/issues/155486#event-29396749961
https://github.com/Fidget-Spinner
Fidget-Spinnerhttps://github.com/Fidget-Spinner
on Aug 13, 2026https://github.com/python/cpython/issues/155486#issuecomment-5279828487
mbeijenhttps://github.com/mbeijen
on Aug 14, 2026https://github.com/python/cpython/issues/155486#event-29455510618
pythongh-155486: Allow non-compact integers in `TO_BOOL_INT` (pythonG…https://github.com/mbeijen/cpython/commit/7a6bc38102704a1f892f3d9cd0b32fff71123bca
pythongh-155486https://github.com/python/cpython/issues/155486
pythonG…https://github.com/python/cpython/pull/155531
7a6bc38https://github.com/mbeijen/cpython/commit/7a6bc38102704a1f892f3d9cd0b32fff71123bca
encukouhttps://github.com/encukou
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Oct 13, 2026https://github.com/python/cpython/issues/155486#event-33122233610
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/155486
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/155486
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
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.