René's URL Explorer Experiment


Title: bpo-32949: Better bytecodes for "with" statement. by markshannon · Pull Request #5112 · python/cpython · GitHub

Open Graph Title: bpo-32949: Better bytecodes for "with" statement. by markshannon · Pull Request #5112 · python/cpython

X Title: bpo-32949: Better bytecodes for "with" statement. by markshannon · Pull Request #5112 · python/cpython

Description: This PR cleans up the interpreter by generating two different code paths for exiting a with statement. One for normal exits and another for the exceptional case. For this function: def foo(): with a: b The bytecode generated changes from: 2 0 LOAD_GLOBAL 0 (a) 2 SETUP_WITH 10 (to 14) 4 POP_TOP 3 6 LOAD_GLOBAL 1 (b) 8 POP_TOP 10 POP_BLOCK 12 BEGIN_FINALLY >> 14 WITH_CLEANUP_START 16 WITH_CLEANUP_FINISH 18 END_FINALLY 20 LOAD_CONST 0 (None) 22 RETURN_VALUE to 2 0 LOAD_GLOBAL 0 (a) 2 SETUP_WITH 20 (to 24) 4 POP_TOP 3 6 LOAD_GLOBAL 1 (b) 8 POP_TOP 10 POP_BLOCK 12 LOAD_CONST 0 (None) 14 DUP_TOP 16 DUP_TOP 18 CALL_FUNCTION 3 20 POP_TOP 22 JUMP_FORWARD 16 (to 40) >> 24 WITH_EXCEPT_START 26 POP_JUMP_IF_TRUE 30 28 RERAISE >> 30 POP_TOP 32 POP_TOP 34 POP_TOP 36 POP_EXCEPT 38 POP_TOP >> 40 LOAD_CONST 0 (None) 42 RETURN_VALUE Although this superficially appears worse, consider the non-exceptional path, after the POP_BLOCK bytecode. before: 12 BEGIN_FINALLY >> 14 WITH_CLEANUP_START 16 WITH_CLEANUP_FINISH 18 END_FINALLY after: 12 LOAD_CONST 0 (None) 14 DUP_TOP 16 DUP_TOP 18 CALL_FUNCTION 3 20 POP_TOP 22 JUMP_FORWARD 16 (to 40) we have replaced several complex and inefficient bytecodes with a few more simpler and faster bytecodes. https://bugs.python.org/issue32949

Open Graph Description: This PR cleans up the interpreter by generating two different code paths for exiting a with statement. One for normal exits and another for the exceptional case. For this function: def foo(): ...

X Description: This PR cleans up the interpreter by generating two different code paths for exiting a with statement. One for normal exits and another for the exceptional case. For this function: def foo(): ...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:b2c02773-46c1-1bdd-d196-dbf2e52a0c78
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA0C0:34E766:1319772:19E08A2:6A557982
html-safe-nonce5878a31e596d5cbfe0719b728e42aab444f972f656e6ab29fb221fd3be1aaf25
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEMwOjM0RTc2NjoxMzE5NzcyOjE5RTA4QTI6NkE1NTc5ODIiLCJ2aXNpdG9yX2lkIjoiNDc3MDkxOTIwNTQwNjM0MTUwNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9e174fa6a89e254ccdf48acfa6831840830d9ee4f51a287e34dbdaa79c7cdece
hovercard-subject-tagpull_request:161484684
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/5112/files
twitter:imagehttps://avatars.githubusercontent.com/u/9448417?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/9448417?s=400&v=4
og:image:altThis PR cleans up the interpreter by generating two different code paths for exiting a with statement. One for normal exits and another for the exceptional case. For this function: def foo(): ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e
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
release617ea94e2807dc3052601c560530bb3f8259bc9a
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/5112/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F5112%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%2F5112%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/5112/files
Reloadhttps://github.com/python/cpython/pull/5112/files
Reloadhttps://github.com/python/cpython/pull/5112/files
Please reload this pagehttps://github.com/python/cpython/pull/5112/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/5112/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
markshannonhttps://github.com/markshannon
python:masterhttps://github.com/python/cpython/tree/master
markshannon:better-with-bytecodeshttps://github.com/markshannon/cpython/tree/better-with-bytecodes
Conversation 3 https://github.com/python/cpython/pull/5112
Commits 6 https://github.com/python/cpython/pull/5112/commits
Checks 0 https://github.com/python/cpython/pull/5112/checks
Files changed https://github.com/python/cpython/pull/5112/files
Please reload this pagehttps://github.com/python/cpython/pull/5112/files
bpo-32949: Better bytecodes for "with" statement. https://github.com/python/cpython/pull/5112/files#top
Show all changes 6 commits https://github.com/python/cpython/pull/5112/files
ece8d8f Produce cleaner bytecode for 'with' and 'async with' by generating se… markshannon Jan 6, 2018 https://github.com/python/cpython/pull/5112/commits/ece8d8f42c7bece2572198631112dcd60a4be3d4
55c32d2 Update importlib markshannon Jan 6, 2018 https://github.com/python/cpython/pull/5112/commits/55c32d2f905a40c4142d282c974a61d141c9a7a8
9ffaa2d Remove unused bytecodes. markshannon Jan 6, 2018 https://github.com/python/cpython/pull/5112/commits/9ffaa2d65d1c34137eeda3d45e4c911872281b51
e9f7689 Update expected results for test_dis. markshannon Jan 6, 2018 https://github.com/python/cpython/pull/5112/commits/e9f7689c01fe9bc84d283ab9d386a13baa4c05e5
7d6ae92 Fix frame.set_lineno to account for new SETUP_WITH and deleete obsolu… markshannon Mar 11, 2018 https://github.com/python/cpython/pull/5112/commits/7d6ae9209794a620ff414959b094e0999bd3b38b
5039d5d New bytecodes for 'with': Add news item and bump magic number. markshannon Mar 13, 2018 https://github.com/python/cpython/pull/5112/commits/5039d5d716a33f6a616e4cafaa624464fb280ec1
Clear filters https://github.com/python/cpython/pull/5112/files
Please reload this pagehttps://github.com/python/cpython/pull/5112/files
Please reload this pagehttps://github.com/python/cpython/pull/5112/files
opcode.h https://github.com/python/cpython/pull/5112/files#diff-1cd1f0bb26c3fbaa279f83ee2bfe1d9072da7af07407111c79039c66034c57ed
_bootstrap_external.py https://github.com/python/cpython/pull/5112/files#diff-efefe383b3a81d16150c280db0b64eed7569254299418f64cc0d749f8e16f3a4
opcode.py https://github.com/python/cpython/pull/5112/files#diff-7681b13de881a13601ca56b73d052d032be48da4256df4f2f09e0474b0c1cbeb
test_dis.py https://github.com/python/cpython/pull/5112/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
2018-03-13-14-46-03.bpo-32949.v821M7.rst https://github.com/python/cpython/pull/5112/files#diff-62d39ae936bb03214315a1ed0d98cf9e5515f57fa1f2720846ceda7e545c0d89
frameobject.c https://github.com/python/cpython/pull/5112/files#diff-7b8cef249e5cca077d30de4e428a6bde6b9b803464e790e9cffa7e052e19efdd
ceval.c https://github.com/python/cpython/pull/5112/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59de
compile.c https://github.com/python/cpython/pull/5112/files#diff-ebc983d9f91e5bcf73500e377ac65e85863c4f77fd5b6b6caf4fcdf7c0f0b057
importlib.h https://github.com/python/cpython/pull/5112/files#diff-f22c3fe718474bf1830c047f516ef95818493a9a9fcf8f2d5b159b1b5b76ecd6
importlib_external.h https://github.com/python/cpython/pull/5112/files#diff-edaa85591e6f559d0fae8073b45dc3e9c8e251053d07623b2ce23392dfe97a7e
opcode_targets.h https://github.com/python/cpython/pull/5112/files#diff-d3363a4083b77b9157d0bf07c2e87f3d3464a8b4360d5d23b07bbb23061f007a
Include/opcode.hhttps://github.com/python/cpython/pull/5112/files#diff-1cd1f0bb26c3fbaa279f83ee2bfe1d9072da7af07407111c79039c66034c57ed
View file https://github.com/markshannon/cpython/blob/5039d5d716a33f6a616e4cafaa624464fb280ec1/Include/opcode.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5112/{{ revealButtonHref }}
https://github.com/python/cpython/pull/5112/files#diff-1cd1f0bb26c3fbaa279f83ee2bfe1d9072da7af07407111c79039c66034c57ed
https://github.com/python/cpython/pull/5112/files#diff-1cd1f0bb26c3fbaa279f83ee2bfe1d9072da7af07407111c79039c66034c57ed
https://github.com/python/cpython/pull/5112/files#diff-1cd1f0bb26c3fbaa279f83ee2bfe1d9072da7af07407111c79039c66034c57ed
Lib/importlib/_bootstrap_external.pyhttps://github.com/python/cpython/pull/5112/files#diff-efefe383b3a81d16150c280db0b64eed7569254299418f64cc0d749f8e16f3a4
View file https://github.com/markshannon/cpython/blob/5039d5d716a33f6a616e4cafaa624464fb280ec1/Lib/importlib/_bootstrap_external.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5112/{{ revealButtonHref }}
https://github.com/python/cpython/pull/5112/files#diff-efefe383b3a81d16150c280db0b64eed7569254299418f64cc0d749f8e16f3a4
https://github.com/python/cpython/pull/5112/files#diff-efefe383b3a81d16150c280db0b64eed7569254299418f64cc0d749f8e16f3a4
https://github.com/python/cpython/pull/5112/files#diff-efefe383b3a81d16150c280db0b64eed7569254299418f64cc0d749f8e16f3a4
Lib/opcode.pyhttps://github.com/python/cpython/pull/5112/files#diff-7681b13de881a13601ca56b73d052d032be48da4256df4f2f09e0474b0c1cbeb
View file https://github.com/markshannon/cpython/blob/5039d5d716a33f6a616e4cafaa624464fb280ec1/Lib/opcode.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5112/{{ revealButtonHref }}
https://github.com/python/cpython/pull/5112/files#diff-7681b13de881a13601ca56b73d052d032be48da4256df4f2f09e0474b0c1cbeb
https://github.com/python/cpython/pull/5112/files#diff-7681b13de881a13601ca56b73d052d032be48da4256df4f2f09e0474b0c1cbeb
https://github.com/python/cpython/pull/5112/files#diff-7681b13de881a13601ca56b73d052d032be48da4256df4f2f09e0474b0c1cbeb
https://github.com/python/cpython/pull/5112/files#diff-7681b13de881a13601ca56b73d052d032be48da4256df4f2f09e0474b0c1cbeb
Lib/test/test_dis.pyhttps://github.com/python/cpython/pull/5112/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
View file https://github.com/markshannon/cpython/blob/5039d5d716a33f6a616e4cafaa624464fb280ec1/Lib/test/test_dis.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5112/{{ revealButtonHref }}
https://github.com/python/cpython/pull/5112/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
https://github.com/python/cpython/pull/5112/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
https://github.com/python/cpython/pull/5112/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
https://github.com/python/cpython/pull/5112/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
https://github.com/python/cpython/pull/5112/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
https://github.com/python/cpython/pull/5112/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
https://github.com/python/cpython/pull/5112/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
https://github.com/python/cpython/pull/5112/files#diff-fd7b118a01a9695dfa16eea9381d3c7b0652e1b7b55f51ff052a1f620d175642
Misc/NEWS.d/next/Core and Builtins/2018-03-13-14-46-03.bpo-32949.v821M7.rsthttps://github.com/python/cpython/pull/5112/files#diff-62d39ae936bb03214315a1ed0d98cf9e5515f57fa1f2720846ceda7e545c0d89
View file https://github.com/markshannon/cpython/blob/5039d5d716a33f6a616e4cafaa624464fb280ec1/Misc/NEWS.d/next/Core%20and%20Builtins/2018-03-13-14-46-03.bpo-32949.v821M7.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5112/{{ revealButtonHref }}
Objects/frameobject.chttps://github.com/python/cpython/pull/5112/files#diff-7b8cef249e5cca077d30de4e428a6bde6b9b803464e790e9cffa7e052e19efdd
View file https://github.com/markshannon/cpython/blob/5039d5d716a33f6a616e4cafaa624464fb280ec1/Objects/frameobject.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5112/{{ revealButtonHref }}
https://github.com/python/cpython/pull/5112/files#diff-7b8cef249e5cca077d30de4e428a6bde6b9b803464e790e9cffa7e052e19efdd
https://github.com/python/cpython/pull/5112/files#diff-7b8cef249e5cca077d30de4e428a6bde6b9b803464e790e9cffa7e052e19efdd
https://github.com/python/cpython/pull/5112/files#diff-7b8cef249e5cca077d30de4e428a6bde6b9b803464e790e9cffa7e052e19efdd
https://github.com/python/cpython/pull/5112/files#diff-7b8cef249e5cca077d30de4e428a6bde6b9b803464e790e9cffa7e052e19efdd
Python/ceval.chttps://github.com/python/cpython/pull/5112/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59de
View file https://github.com/markshannon/cpython/blob/5039d5d716a33f6a616e4cafaa624464fb280ec1/Python/ceval.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5112/{{ revealButtonHref }}
https://github.com/python/cpython/pull/5112/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59de
https://github.com/python/cpython/pull/5112/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59de
https://github.com/python/cpython/pull/5112/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59de
https://github.com/python/cpython/pull/5112/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59de
https://github.com/python/cpython/pull/5112/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59de
https://github.com/python/cpython/pull/5112/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59de
Please reload this pagehttps://github.com/python/cpython/pull/5112/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.