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
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:b2c02773-46c1-1bdd-d196-dbf2e52a0c78 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A0C0:34E766:1319772:19E08A2:6A557982 |
| html-safe-nonce | 5878a31e596d5cbfe0719b728e42aab444f972f656e6ab29fb221fd3be1aaf25 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEMwOjM0RTc2NjoxMzE5NzcyOjE5RTA4QTI6NkE1NTc5ODIiLCJ2aXNpdG9yX2lkIjoiNDc3MDkxOTIwNTQwNjM0MTUwNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9e174fa6a89e254ccdf48acfa6831840830d9ee4f51a287e34dbdaa79c7cdece |
| hovercard-subject-tag | pull_request:161484684 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/5112/files |
| twitter:image | https://avatars.githubusercontent.com/u/9448417?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/9448417?s=400&v=4 |
| og:image:alt | 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(): ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 617ea94e2807dc3052601c560530bb3f8259bc9a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width