René's URL Explorer Experiment


Title: gh-138912: Add dedicated opcodes for MatchClass without positional sub-patterns by cdce8p · Pull Request #139080 · python/cpython · GitHub

Open Graph Title: gh-138912: Add dedicated opcodes for MatchClass without positional sub-patterns by cdce8p · Pull Request #139080 · python/cpython

X Title: gh-138912: Add dedicated opcodes for MatchClass without positional sub-patterns by cdce8p · Pull Request #139080 · python/cpython

Description: This PR complements and extends the work done in #138915. In a microbenchmark for bare class matches, the match statement is now even slightly faster than the comparable if statement. With keyword only patterns, the performance is much improved as it's no longer necessary to construct intermediary tuples so that's now only ~20% slower compared to the if equivalent. (Previously it was closer to ~220%). Further improvements can likely be archived if MATCH_CLASS_GET_OPT_ATTR is specialized in a similar manner to LOAD_ATTR. With the specialization for (just) LOAD_ATTR disabled, the match statement equivalent is again slightly faster than the corresponding if clause. __ Micro benchmarks with all specializations enabled. Micro benchmark (bare class pattern) from timeit import timeit setup = """ class A: def __init__(self, x, y): self.x = x self.y = y a = A(1, 2) def f1(a): if isinstance(a, A): return True return False def f2(a): match a: case A(): return True return False """ print(f"If\t{timeit("f1(a)", setup, number=10**7)}") print(f"Match\t{timeit("f2(a)", setup, number=10**7)}") # Before If 0.29646458296338096 Match 0.6549855829798616 # After If 0.2934637920006935 Match 0.2751032500018482 -> -58% Micro benchmark (One keyword attribute) from timeit import timeit setup = """ class A: def __init__(self, x, y): self.x = x self.y = y a = A(1, 2) def f1(a): if isinstance(a, A) and a.x == 1: return True return False def f2(a): match a: case A(x=1): return True return False """ print(f"If\t{timeit("f1(a)", setup, number=10**7)}") print(f"Match\t{timeit("f2(a)", setup, number=10**7)}") # Before If 0.35557704203529283 Match 1.1494590829825029 # After If 0.3604730829974869 Match 0.45169049999822164 -> -61% Issue: gh-138912 📚 Documentation preview 📚: https://cpython-previews--139080.org.readthedocs.build/

Open Graph Description: This PR complements and extends the work done in #138915. In a microbenchmark for bare class matches, the match statement is now even slightly faster than the comparable if statement. With keyword ...

X Description: This PR complements and extends the work done in #138915. In a microbenchmark for bare class matches, the match statement is now even slightly faster than the comparable if statement. With keyword ...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:d9f6a476-4daf-a5be-e227-326b6ac3ff1b
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id8F82:FB8AB:3734A1:4B9155:6A5142F4
html-safe-noncef6ee2ae18e21654f77dafce395067fb76c310305f7db651a45ef778835ab1cd6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjgyOkZCOEFCOjM3MzRBMTo0QjkxNTU6NkE1MTQyRjQiLCJ2aXNpdG9yX2lkIjoiODM3MDI3ODQ3MTgwNzMxMTI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac148279c19532f3194a4171fc7105924e4d14fe84e90a5aa7b20c0bd760cadd21
hovercard-subject-tagpull_request:2837902882
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/139080/files
twitter:imagehttps://avatars.githubusercontent.com/u/30130371?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/30130371?s=400&v=4
og:image:altThis PR complements and extends the work done in #138915. In a microbenchmark for bare class matches, the match statement is now even slightly faster than the comparable if statement. With keyword ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonee840f405b2718e8f2d55aafa9ff27dbce17e29d0c253011d05ea0fea3c78baff
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
releaseb78565f6aa43cc5323c9935ec11b22cca7bb0a62
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/139080/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F139080%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%2F139080%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/139080/files
Reloadhttps://github.com/python/cpython/pull/139080/files
Reloadhttps://github.com/python/cpython/pull/139080/files
Please reload this pagehttps://github.com/python/cpython/pull/139080/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/139080/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.7k 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
cdce8phttps://github.com/cdce8p
python:mainhttps://github.com/python/cpython/tree/main
cdce8p:match-class-opcodeshttps://github.com/cdce8p/cpython/tree/match-class-opcodes
Conversation 11 https://github.com/python/cpython/pull/139080
Commits 19 https://github.com/python/cpython/pull/139080/commits
Checks 74 https://github.com/python/cpython/pull/139080/checks
Files changed https://github.com/python/cpython/pull/139080/files
Please reload this pagehttps://github.com/python/cpython/pull/139080/files
gh-138912: Add dedicated opcodes for MatchClass without positional sub-patterns https://github.com/python/cpython/pull/139080/files#top
Show all changes 19 commits https://github.com/python/cpython/pull/139080/files
ed93ca1 gh-138912: Add dedicated opcodes for MatchClass without positional su… cdce8p Sep 17, 2025 https://github.com/python/cpython/pull/139080/commits/ed93ca10a94c3ece7123ee37b453a95fbcf2da9d
2ee12ab Fix ADDOP_JUMP cdce8p Sep 17, 2025 https://github.com/python/cpython/pull/139080/commits/2ee12ab595f7069918294a762f2bf7b7c69ba3b3
d0e7315 Fix peephole tests cdce8p Sep 17, 2025 https://github.com/python/cpython/pull/139080/commits/d0e73159033d8dc9df23ae35f3c58b9b91aab43a
64692e6 Fix embed test cdce8p Sep 17, 2025 https://github.com/python/cpython/pull/139080/commits/64692e6a8a129c52cdbe8e26915f11e8dbad845e
3314ccd Merge branch 'main' cdce8p Nov 20, 2025 https://github.com/python/cpython/pull/139080/commits/3314ccdd9ecb74bd954c463f8334c67bb7409a96
a78e36a Merge branch 'main' cdce8p Dec 21, 2025 https://github.com/python/cpython/pull/139080/commits/a78e36aaf63f332f9c8fc465dae28d337a81f4ab
8833828 Merge branch 'main' cdce8p Jan 12, 2026 https://github.com/python/cpython/pull/139080/commits/88338280e83a42608986806ad3ccb3ab8fd11be9
b3ccb13 Merge branch 'main' cdce8p Jan 24, 2026 https://github.com/python/cpython/pull/139080/commits/b3ccb13741fff36cd72d5dc8ed26be8fe37441ec
f1bccb2 Merge branch 'main' into match-class-opcodes cdce8p Jan 24, 2026 https://github.com/python/cpython/pull/139080/commits/f1bccb2a949a6c742885d64ed5e0e2c81605ff7d
54d54cb Merge branch 'main' cdce8p Feb 1, 2026 https://github.com/python/cpython/pull/139080/commits/54d54cb3db644c398b47b25b27f69fe5866cf6ae
a96e128 Merge branch 'main' cdce8p Feb 14, 2026 https://github.com/python/cpython/pull/139080/commits/a96e128ba7f6442185188c136fcac6fecd06fdbf
bdfd74f Merge branch 'main' cdce8p Mar 14, 2026 https://github.com/python/cpython/pull/139080/commits/bdfd74ffbfff6f8b23220baa9972d16c7dfa7353
055b019 Fix test case cdce8p Mar 14, 2026 https://github.com/python/cpython/pull/139080/commits/055b0191c579da11d52abbf2b4574d9eb8294e09
9f50bc8 Merge branch 'main' cdce8p Mar 23, 2026 https://github.com/python/cpython/pull/139080/commits/9f50bc8f28eb5bd690c376c1ccfc51fea950d65a
98ce759 Merge branch 'main' cdce8p Apr 12, 2026 https://github.com/python/cpython/pull/139080/commits/98ce759b2b92969b196f8275cba74277f9e63939
1da12a6 Merge branch 'main' cdce8p Apr 21, 2026 https://github.com/python/cpython/pull/139080/commits/1da12a6c0a5d26b37b1d34f916a8e25db81a53e3
0a0e3a4 Merge branch 'main' cdce8p May 8, 2026 https://github.com/python/cpython/pull/139080/commits/0a0e3a4d8353c324ae4fb50f576633f9e1f064c4
90fa9eb Merge branch 'main' cdce8p Jun 24, 2026 https://github.com/python/cpython/pull/139080/commits/90fa9ebf18710d2b72545aa8acc65ba203d33e3b
765dd36 Merge branch 'main' cdce8p Jun 29, 2026 https://github.com/python/cpython/pull/139080/commits/765dd36f7a7b254d8769ac6698fe694dff683cc9
Clear filters https://github.com/python/cpython/pull/139080/files
Please reload this pagehttps://github.com/python/cpython/pull/139080/files
Please reload this pagehttps://github.com/python/cpython/pull/139080/files
dis.rst https://github.com/python/cpython/pull/139080/files#diff-eaa488fc50d23b30ca8b24ab19e9c91c1c941339847af993e908f006eec0653b
pycore_magic_number.h https://github.com/python/cpython/pull/139080/files#diff-cab675717b887b20316ee0113f1e44bbd5db4e4a6e04ff75eb3996deffeafed4
pycore_opcode_metadata.h https://github.com/python/cpython/pull/139080/files#diff-72bc4c0445516cc3eabd536220b2459617491ffaabbdb8a7c5381f36c991e378
pycore_uop_ids.h https://github.com/python/cpython/pull/139080/files#diff-2a420e4d0d58009249c0f73f7c822167b053bd51cb213b20179bd2aebfc66ff9
pycore_uop_metadata.h https://github.com/python/cpython/pull/139080/files#diff-55e65a72fa31e9b746e03076d2c74b716c0c1171663f36960b2339fcbfae9bab
opcode_ids.h https://github.com/python/cpython/pull/139080/files#diff-e4ecf20b65dcacb3c91fc910b83d99a2ca60282b51aa65e7902a662c227e6187
_opcode_metadata.py https://github.com/python/cpython/pull/139080/files#diff-3f2acff9cdbb005de538e3ba43dc12406bf414047d7d018476bac0048b5056e4
test_opt.py https://github.com/python/cpython/pull/139080/files#diff-67b5bd915e37f77df79907865982648172c27d3b96fbb072b30a73c6a2735439
test_dis.py https://github.com/python/cpython/pull/139080/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
test_peepholer.py https://github.com/python/cpython/pull/139080/files#diff-bcf92ed219340e9e0c52401909828c2e9a821541660073e24d64dd996beaf842
2025-09-17-22-12-38.gh-issue-138912.PijFSS.rst https://github.com/python/cpython/pull/139080/files#diff-1aee2f5fafa534c058ec8276178a4295624921949e2da037d129532b43be7656
test_cases.c.h https://github.com/python/cpython/pull/139080/files#diff-2852a58ed53ab1473b74dbdc4165885a9b74865b6d71e48fa4813d6289fa1838
test_targets.h https://github.com/python/cpython/pull/139080/files#diff-096e9952e325d9c098b3f85e87e7f41369678d0f019f26c8772531146896d50d
test_frozenmain.h https://github.com/python/cpython/pull/139080/files#diff-dcbbf153f77c69fb3a08746516bb9baaf46b9465c941221d1d495123e92cc862
bytecodes.c https://github.com/python/cpython/pull/139080/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342
ceval.c https://github.com/python/cpython/pull/139080/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59de
codegen.c https://github.com/python/cpython/pull/139080/files#diff-6d58b0ddc066ad12ebc378b62c4189335bd57c83aece11072c76fd86a78a1a4a
executor_cases.c.h https://github.com/python/cpython/pull/139080/files#diff-a1c3430c42a66c16e6d2e154491a6da993b187b27c628545a12a02c7b2a06b81
generated_cases.c.h https://github.com/python/cpython/pull/139080/files#diff-4ef46fa654f95502e49a24f7dc8ee31a4cac9b3433fe9cd2b2d4dd78cfbad448
opcode_targets.h https://github.com/python/cpython/pull/139080/files#diff-d3363a4083b77b9157d0bf07c2e87f3d3464a8b4360d5d23b07bbb23061f007a
optimizer_cases.c.h https://github.com/python/cpython/pull/139080/files#diff-ed4567b3e67709ec57bf4df91ef058cfcbe00d7da11cd2a75e38241fa1ca99d2
Doc/library/dis.rsthttps://github.com/python/cpython/pull/139080/files#diff-eaa488fc50d23b30ca8b24ab19e9c91c1c941339847af993e908f006eec0653b
View file https://github.com/python/cpython/blob/765dd36f7a7b254d8769ac6698fe694dff683cc9/Doc/library/dis.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/139080/{{ revealButtonHref }}
https://github.com/python/cpython/pull/139080/files#diff-eaa488fc50d23b30ca8b24ab19e9c91c1c941339847af993e908f006eec0653b
https://github.com/python/cpython/pull/139080/files#diff-eaa488fc50d23b30ca8b24ab19e9c91c1c941339847af993e908f006eec0653b
Include/internal/pycore_magic_number.hhttps://github.com/python/cpython/pull/139080/files#diff-cab675717b887b20316ee0113f1e44bbd5db4e4a6e04ff75eb3996deffeafed4
View file https://github.com/python/cpython/blob/765dd36f7a7b254d8769ac6698fe694dff683cc9/Include/internal/pycore_magic_number.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/139080/{{ revealButtonHref }}
https://github.com/python/cpython/pull/139080/files#diff-cab675717b887b20316ee0113f1e44bbd5db4e4a6e04ff75eb3996deffeafed4
https://github.com/python/cpython/pull/139080/files#diff-cab675717b887b20316ee0113f1e44bbd5db4e4a6e04ff75eb3996deffeafed4
https://github.com/python/cpython/pull/139080/files#diff-cab675717b887b20316ee0113f1e44bbd5db4e4a6e04ff75eb3996deffeafed4
Include/internal/pycore_opcode_metadata.hhttps://github.com/python/cpython/pull/139080/files#diff-72bc4c0445516cc3eabd536220b2459617491ffaabbdb8a7c5381f36c991e378
View file https://github.com/python/cpython/blob/765dd36f7a7b254d8769ac6698fe694dff683cc9/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/139080/files
Please reload this pagehttps://github.com/python/cpython/pull/139080/files
Please reload this pagehttps://github.com/python/cpython/pull/139080/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.