Title: Optimizing FOR_ITER bytecode · Issue #91432 · python/cpython · GitHub
Open Graph Title: Optimizing FOR_ITER bytecode · Issue #91432 · python/cpython
X Title: Optimizing FOR_ITER bytecode · Issue #91432 · python/cpython
Description: We can execute one less opcode in every iteration (except for the first) of every for-loop by changing from GET_ITER top: FOR_ITER [body] JUMP_BACKWARDS(top) cleanup: end: to GET_ITER JUMP_FORWARD(bottom) body: [body] bottom: FOR_END(bod...
Open Graph Description: We can execute one less opcode in every iteration (except for the first) of every for-loop by changing from GET_ITER top: FOR_ITER [body] JUMP_BACKWARDS(top) cleanup: end: to GET_ITER JUMP_FORWARD(...
X Description: We can execute one less opcode in every iteration (except for the first) of every for-loop by changing from GET_ITER top: FOR_ITER [body] JUMP_BACKWARDS(top) cleanup: end: to GET_ITER JUMP_FORWARD(...
Opengraph URL: https://github.com/python/cpython/issues/91432
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Optimizing FOR_ITER bytecode","articleBody":"We can execute one less opcode in every iteration (except for the first) of every for-loop by changing from\r\n\r\n```\r\n GET_ITER\r\ntop:\r\n FOR_ITER\r\n [body]\r\n JUMP_BACKWARDS(top)\r\ncleanup:\r\nend:\r\n```\r\n\r\nto\r\n\r\n```\r\n GET_ITER\r\n JUMP_FORWARD(bottom)\r\nbody:\r\n [body]\r\nbottom:\r\n FOR_END(body)\r\ncleanup:\r\nend:\r\n```\r\n\r\nThis was suggested by @markshannon [here](https://github.com/faster-cpython/ideas/issues/67#issuecomment-881358019), but it appears to be similar in spirit to [Loop Inversion](https://en.wikipedia.org/wiki/Loop_inversion).\r\n\r\nThere seems to be a small (on the order of 1%) benefit, but I imagine the benefit will be magnified after any specialization.","author":{"url":"https://github.com/sweeneyde","@type":"Person","name":"sweeneyde"},"datePublished":"2022-04-10T23:28:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/91432/cpython/issues/91432"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f852c8b5-730f-982e-fcb6-518fef86ea79 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CFEC:256EA0:12BA4DB:1909B6B:6969AD28 |
| html-safe-nonce | 95809c5da4e573686f5195e06090ba09fcdf0a85ac285eca562255ace8fce00b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRkVDOjI1NkVBMDoxMkJBNERCOjE5MDlCNkI6Njk2OUFEMjgiLCJ2aXNpdG9yX2lkIjoiNDE1MDUwNTYyMTc5NjAwNzIwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 798ea4433dfa5de6d8ed2777a86c0d0ce8e4a761869d9d8f23fedebf95bd2230 |
| hovercard-subject-tag | issue:1199219945 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/91432/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b5362f2f73675f25429817957efd075d2c3a00e4195743c3c6f676decc6e039c/python/cpython/issues/91432 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b5362f2f73675f25429817957efd075d2c3a00e4195743c3c6f676decc6e039c/python/cpython/issues/91432 |
| og:image:alt | We can execute one less opcode in every iteration (except for the first) of every for-loop by changing from GET_ITER top: FOR_ITER [body] JUMP_BACKWARDS(top) cleanup: end: to GET_ITER JUMP_FORWARD(... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sweeneyde |
| hostname | github.com |
| expected-hostname | github.com |
| None | 24c4c97a2d520cb286b35e1a4c22d7a4df3c26a2fa28dd7cdf0e65db327b4de7 |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 124667f43168afb6c9c03b7c02eb5b1d2e1be3d9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width