René's URL Explorer Experiment


Title: gh-143732: Add tier2 specialization for TO_BOOL by eendebakpt · Pull Request #148271 · python/cpython · GitHub

Open Graph Title: gh-143732: Add tier2 specialization for TO_BOOL by eendebakpt · Pull Request #148271 · python/cpython

X Title: gh-143732: Add tier2 specialization for TO_BOOL by eendebakpt · Pull Request #148271 · python/cpython

Description: See discussion at #148113. (description updated after refactoring) This PR adds two tier2 opcodes for specialization of TO_BOOL. The *args and **kwargs arguments are marked in tier2 as tuple and dict, respectively. A recording uop is added to TO_BOOL. Benchmark main branch Speedup to_bool_dict_recorded 1.21 sec 852 ms 1.41× to_bool_tuple_recorded 1.21 sec 850 ms 1.42× to_bool_bytes_true 1.20 sec 852 ms 1.41× to_bool_bytes_false 922 ms 566 ms 1.63× to_bool_bytearray 1.20 sec 851 ms 1.41× to_bool_set_recorded 1.23 sec 849 ms 1.45× to_bool_frozenset 1.23 sec 850 ms 1.45× to_bool_kwargs_nonempty 1.26 sec 912 ms 1.38× to_bool_kwargs_empty 952 ms 576 ms 1.65× to_bool_varargs_nonempty 1.23 sec 892 ms 1.38× to_bool_varargs_empty 933 ms 574 ms 1.62× to_bool_set_literal 26.3 ms 24.6 ms 1.07× Geometric mean (ref) 1.43× Details """TO_BOOL specialization benchmark. Covers both the static (sym_get_type) and recorded (sym_get_probable_type) paths through the JIT optimizer's _TO_BOOL rule. Static path: - kwargs dict (via **kwargs slot priming) - varargs tuple (via *args slot priming) - set literal (via _BUILD_SET) Recorded path (only reached via _RECORD_TOS_TYPE; bytes/bytearray/frozenset have no static-type construction at all): - dict / tuple / bytes / bytearray / set / frozenset passed as parameter """ import pyperf INNER_ITERS = 200 # ---- recorded-type path: value comes in as a parameter, no static type ---- def _recorded_inner(v): cnt = 0 for _ in range(INNER_ITERS): if v: cnt += 1 return cnt def to_bool_dict_recorded(n): d = {"a": 1} for _ in range(n): _recorded_inner(d) def to_bool_tuple_recorded(n): t = (1, 2, 3) for _ in range(n): _recorded_inner(t) def to_bool_bytes_true(n): b = b"hello" for _ in range(n): _recorded_inner(b) def to_bool_bytes_false(n): b = b"" for _ in range(n): _recorded_inner(b) def to_bool_bytearray(n): b = bytearray(b"hello") for _ in range(n): _recorded_inner(b) def to_bool_set_recorded(n): s = {1, 2, 3} for _ in range(n): _recorded_inner(s) def to_bool_frozenset(n): s = frozenset({1, 2, 3}) for _ in range(n): _recorded_inner(s) # ---- static-type path: kwargs / varargs slot priming ---- def _kwargs_inner(**kwargs): cnt = 0 for _ in range(INNER_ITERS): if kwargs: cnt += 1 return cnt def _varargs_inner(*args): cnt = 0 for _ in range(INNER_ITERS): if args: cnt += 1 return cnt def to_bool_kwargs_nonempty(n): for _ in range(n): _kwargs_inner(x=1, y=2) def to_bool_kwargs_empty(n): for _ in range(n): _kwargs_inner() def to_bool_varargs_nonempty(n): for _ in range(n): _varargs_inner(1, 2, 3) def to_bool_varargs_empty(n): for _ in range(n): _varargs_inner() # ---- static-type path: set literal via _BUILD_SET ---- def to_bool_set_literal(n): cnt = 0 for _ in range(n): s = {1} if s: cnt += 1 return cnt N = 500_000 runner = pyperf.Runner() runner.bench_func("to_bool_dict_recorded", to_bool_dict_recorded, N) runner.bench_func("to_bool_tuple_recorded", to_bool_tuple_recorded, N) runner.bench_func("to_bool_bytes_true", to_bool_bytes_true, N) runner.bench_func("to_bool_bytes_false", to_bool_bytes_false, N) runner.bench_func("to_bool_bytearray", to_bool_bytearray, N) runner.bench_func("to_bool_set_recorded", to_bool_set_recorded, N) runner.bench_func("to_bool_frozenset", to_bool_frozenset, N) runner.bench_func("to_bool_kwargs_nonempty", to_bool_kwargs_nonempty, N) runner.bench_func("to_bool_kwargs_empty", to_bool_kwargs_empty, N) runner.bench_func("to_bool_varargs_nonempty", to_bool_varargs_nonempty, N) runner.bench_func("to_bool_varargs_empty", to_bool_varargs_empty, N) runner.bench_func("to_bool_set_literal", to_bool_set_literal, N) Issue: gh-143732

Open Graph Description: See discussion at #148113. (description updated after refactoring) This PR adds two tier2 opcodes for specialization of TO_BOOL. The *args and **kwargs arguments are marked in tier2 as tuple and di...

X Description: See discussion at #148113. (description updated after refactoring) This PR adds two tier2 opcodes for specialization of TO_BOOL. The *args and **kwargs arguments are marked in tier2 as tuple and di...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:697d063f-1143-18d1-2551-0d659b44d02c
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id86FE:3A486F:1CC0411:270AB02:6A537223
html-safe-nonce50f9cf51b057fe3611389ca5ea0a37eb02297ca60fc5a5a7576d10aa01e0085e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NkZFOjNBNDg2RjoxQ0MwNDExOjI3MEFCMDI6NkE1MzcyMjMiLCJ2aXNpdG9yX2lkIjoiNzQ1MzUyOTg0MTE4MDMwODAwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacf95c2a44ddab8ee5b4f9f36b9289845ef27fda8203355f883418ecb42e68e101
hovercard-subject-tagpull_request:3505520038
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/148271/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:altSee discussion at #148113. (description updated after refactoring) This PR adds two tier2 opcodes for specialization of TO_BOOL. The *args and **kwargs arguments are marked in tier2 as tuple and di...
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/148271/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F148271%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%2F148271%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/148271/files
Reloadhttps://github.com/python/cpython/pull/148271/files
Reloadhttps://github.com/python/cpython/pull/148271/files
Please reload this pagehttps://github.com/python/cpython/pull/148271/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/148271/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
eendebakpthttps://github.com/eendebakpt
python:mainhttps://github.com/python/cpython/tree/main
eendebakpt:to_bool_specializationhttps://github.com/eendebakpt/cpython/tree/to_bool_specialization
Conversation 16 https://github.com/python/cpython/pull/148271
Commits 31 https://github.com/python/cpython/pull/148271/commits
Checks 74 https://github.com/python/cpython/pull/148271/checks
Files changed https://github.com/python/cpython/pull/148271/files
Please reload this pagehttps://github.com/python/cpython/pull/148271/files
gh-143732: Add tier2 specialization for TO_BOOL https://github.com/python/cpython/pull/148271/files#top
Show all changes 31 commits https://github.com/python/cpython/pull/148271/files
d35071a Add specializations for TO_BOOL eendebakpt Apr 8, 2026 https://github.com/python/cpython/pull/148271/commits/d35071a533c79240abb4e9a0e5af053ee118e5a0
44f5c49 type information for kwargs eendebakpt Apr 8, 2026 https://github.com/python/cpython/pull/148271/commits/44f5c49acdf5910c8bc2cf2d90a1ec25421236e1
b80a79b add tests eendebakpt Apr 8, 2026 https://github.com/python/cpython/pull/148271/commits/b80a79b7ca37f0fce208b54d931cde894f15c9ad
ba88f27 Merge branch 'main' into to_bool_specialization eendebakpt Apr 8, 2026 https://github.com/python/cpython/pull/148271/commits/ba88f274ad4b2886d872fa4b05c61c3d22b5249b
29311d8 review comments eendebakpt Apr 10, 2026 https://github.com/python/cpython/pull/148271/commits/29311d860a562157c790df696a9d73073c811aba
e9c1e24 Merge branch 'main' into to_bool_specialization eendebakpt Apr 10, 2026 https://github.com/python/cpython/pull/148271/commits/e9c1e24aab75445fa882e3a088af6636f34deb3c
9de1c2c fix merge conflict eendebakpt Apr 10, 2026 https://github.com/python/cpython/pull/148271/commits/9de1c2ccf273231a6e289dff5b39bdfeec0008ab
91334af Merge branch 'main' into to_bool_specialization eendebakpt Apr 12, 2026 https://github.com/python/cpython/pull/148271/commits/91334af7e84d0c6ea05d2f6cf6f38fe0539f77ca
08a4535 Merge branch 'main' into to_bool_specialization eendebakpt Apr 14, 2026 https://github.com/python/cpython/pull/148271/commits/08a4535160c59754b62f2e115fc3a8363cc6ab13
62fae72 add regression test for set eendebakpt Apr 14, 2026 https://github.com/python/cpython/pull/148271/commits/62fae72be016aebfd3ab06a07d4abe42b2a7b591
52f7cc6 review comments eendebakpt Apr 14, 2026 https://github.com/python/cpython/pull/148271/commits/52f7cc6737eb6a14726eeb205e8795405243453b
05c6089 handle set case eendebakpt Apr 14, 2026 https://github.com/python/cpython/pull/148271/commits/05c6089fbcfa9be43c631cc2f60415589f830862
d655709 remove dead code eendebakpt Apr 14, 2026 https://github.com/python/cpython/pull/148271/commits/d65570930183c0931773abe3ca5ac35173a77727
3984a31 Merge branch 'main' into to_bool_specialization eendebakpt Apr 22, 2026 https://github.com/python/cpython/pull/148271/commits/3984a318e2c2e55c2e17884195149a251be8903c
0606e89 regenerate eendebakpt Apr 22, 2026 https://github.com/python/cpython/pull/148271/commits/0606e89c9bccbc0f85881b8d74583139bf2546b9
578a6e0 Merge branch 'to_bool_specialization_v2' into to_bool_specialization eendebakpt Apr 30, 2026 https://github.com/python/cpython/pull/148271/commits/578a6e0143709205d700f8c23e26eb34596aa9c8
1e01851 Merge remote-tracking branch 'origin/main' into to_bool_specialization eendebakpt Apr 30, 2026 https://github.com/python/cpython/pull/148271/commits/1e018513de61f003e60e15a5910d7aafb56c405a
bb35e19 fix merge conflicts and add recording uop eendebakpt Apr 30, 2026 https://github.com/python/cpython/pull/148271/commits/bb35e19b6bcdaf04406a8b47e033ffda02a50a43
f9a8bc5 cleanup eendebakpt Apr 30, 2026 https://github.com/python/cpython/pull/148271/commits/f9a8bc5768fb7266caec80da374873e73961c0b5
ee0325c Merge remote-tracking branch 'origin/main' into to_bool_specializatio… eendebakpt Apr 30, 2026 https://github.com/python/cpython/pull/148271/commits/ee0325cffa16de15ce455932d7053ea5f2830a21
c7daa03 Restore test_opt.py from origin/main, re-applying TO_BOOL tests eendebakpt Apr 30, 2026 https://github.com/python/cpython/pull/148271/commits/c7daa032ae801e962f2badb13ae72056e9c4e7f4
e9a1e9a add more tests, remove defensive code eendebakpt May 1, 2026 https://github.com/python/cpython/pull/148271/commits/e9a1e9a419db97a7e70deb6fc6a7df68f37d5d9b
09c07a3 news entry eendebakpt May 1, 2026 https://github.com/python/cpython/pull/148271/commits/09c07a32bc5f89acd81fc44dfe626f0b16ad7627
c64d69d Merge remote-tracking branch 'origin/main' into to_bool_specialization eendebakpt May 1, 2026 https://github.com/python/cpython/pull/148271/commits/c64d69df8bc6cefe977c76948c7d595ae533a9be
06247eb Merge branch 'main' into to_bool_specialization eendebakpt May 1, 2026 https://github.com/python/cpython/pull/148271/commits/06247eb0e7ea4c6c33f2c96f2fde18a80855de67
a30ca62 Merge branch 'main' into to_bool_specialization eendebakpt May 1, 2026 https://github.com/python/cpython/pull/148271/commits/a30ca62543bbf9b4c193d6d702285593549bad5e
fa17d1d Merge branch 'main' into to_bool_specialization eendebakpt May 3, 2026 https://github.com/python/cpython/pull/148271/commits/fa17d1d0452cee8efb5cd5e2f85dd39415beec67
cd540b8 Merge branch 'main' into pr-148271 eendebakpt May 18, 2026 https://github.com/python/cpython/pull/148271/commits/cd540b87d6e0a23d31349686c03d0dcfd3c06cad
729ecc9 add frozendict eendebakpt May 18, 2026 https://github.com/python/cpython/pull/148271/commits/729ecc99ffd742a45ef687816f342eb57bc60d7b
5d3090a Merge branch 'main' into to_bool_specialization eendebakpt May 22, 2026 https://github.com/python/cpython/pull/148271/commits/5d3090ad0670ec9a89226e5fbc882b9414d86c1d
43c54d4 refactor tests eendebakpt May 22, 2026 https://github.com/python/cpython/pull/148271/commits/43c54d4a1006eb4f69b99b32bade7d162ee4a623
Clear filters https://github.com/python/cpython/pull/148271/files
Please reload this pagehttps://github.com/python/cpython/pull/148271/files
Please reload this pagehttps://github.com/python/cpython/pull/148271/files
pycore_opcode_metadata.h https://github.com/python/cpython/pull/148271/files#diff-72bc4c0445516cc3eabd536220b2459617491ffaabbdb8a7c5381f36c991e378
pycore_uop_ids.h https://github.com/python/cpython/pull/148271/files#diff-2a420e4d0d58009249c0f73f7c822167b053bd51cb213b20179bd2aebfc66ff9
pycore_uop_metadata.h https://github.com/python/cpython/pull/148271/files#diff-55e65a72fa31e9b746e03076d2c74b716c0c1171663f36960b2339fcbfae9bab
test_opt.py https://github.com/python/cpython/pull/148271/files#diff-67b5bd915e37f77df79907865982648172c27d3b96fbb072b30a73c6a2735439
2026-05-01-12-00-00.gh-issue-143732.aI0bt4.rst https://github.com/python/cpython/pull/148271/files#diff-1df01de1cb1fe1e36ca8095fc719ccc4eb634a2a97d8aa117e8f7f81e2fa808f
bytecodes.c https://github.com/python/cpython/pull/148271/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342
executor_cases.c.h https://github.com/python/cpython/pull/148271/files#diff-a1c3430c42a66c16e6d2e154491a6da993b187b27c628545a12a02c7b2a06b81
optimizer_bytecodes.c https://github.com/python/cpython/pull/148271/files#diff-e5bd2b14b0b10f0f47786e26306d689ed1361c3dc3b11dcc3ea52b8a2422ff64
optimizer_cases.c.h https://github.com/python/cpython/pull/148271/files#diff-ed4567b3e67709ec57bf4df91ef058cfcbe00d7da11cd2a75e38241fa1ca99d2
optimizer_symbols.c https://github.com/python/cpython/pull/148271/files#diff-b28c00f0aab70992e604ed7c3e9cb4ca39779f33d5ff2c7777de5a044422f095
record_functions.c.h https://github.com/python/cpython/pull/148271/files#diff-ac2bf70082a97de53db16bbb949b29240f59f89c4b9ad93928b3926738cbb74c
Include/internal/pycore_opcode_metadata.hhttps://github.com/python/cpython/pull/148271/files#diff-72bc4c0445516cc3eabd536220b2459617491ffaabbdb8a7c5381f36c991e378
View file https://github.com/python/cpython/blob/43c54d4a1006eb4f69b99b32bade7d162ee4a623/Include/internal/pycore_opcode_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/148271/files
Please reload this pagehttps://github.com/python/cpython/pull/148271/files
Please reload this pagehttps://github.com/python/cpython/pull/148271/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.