Title: Add return const instruction · Issue #101632 · python/cpython · GitHub
Open Graph Title: Add return const instruction · Issue #101632 · python/cpython
X Title: Add return const instruction · Issue #101632 · python/cpython
Description: From the pystats doc (pystats-2023-02-05-python-5a2b984.md), I find that LOAD_CONST + RETURN_VALUE is a very high frequency (Because the default return of the function is None). Successors for LOAD_CONST Successors Count Percentage RETUR...
Open Graph Description: From the pystats doc (pystats-2023-02-05-python-5a2b984.md), I find that LOAD_CONST + RETURN_VALUE is a very high frequency (Because the default return of the function is None). Successors for LOAD...
X Description: From the pystats doc (pystats-2023-02-05-python-5a2b984.md), I find that LOAD_CONST + RETURN_VALUE is a very high frequency (Because the default return of the function is None). Successors for LOAD...
Opengraph URL: https://github.com/python/cpython/issues/101632
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add return const instruction","articleBody":"From the pystats doc ([pystats-2023-02-05-python-5a2b984.md](https://github.com/faster-cpython/ideas/blob/main/stats/pystats-2023-02-05-python-5a2b984.md)), I find that `LOAD_CONST + RETURN_VALUE` is a very high frequency (Because the default return of the function is None).\r\n\r\n\r\nSuccessors for LOAD_CONST \r\n\r\nSuccessors | Count | Percentage\r\n-- | -- | --\r\nRETURN_VALUE | 969,173,651 | 21.8%\r\nBINARY_OP_ADD_INT | 418,647,997 | 9.4%\r\nLOAD_CONST | 403,185,774 | 9.1%\r\nCOMPARE_AND_BRANCH_INT | 314,633,792 | 7.1%\r\nSTORE_FAST | 295,563,626 | 6.6%\r\n\r\nAnd predecessors for RETURN_VALUE\r\n\r\nPredecessors | Count | Percentage\r\n-- | -- | --\r\nLOAD_CONST | 969,173,651 | 29.9%\r\nLOAD_FAST | 505,933,343 | 15.6%\r\nRETURN_VALUE | 382,698,373 | 11.8%\r\nBUILD_TUPLE | 328,532,240 | 10.1%\r\nCOMPARE_OP | 107,210,803 | 3.3%\r\n\r\nThis means that if we add a `RETURN_CONST`, we can reduce the `RETURN_VALUE` instruction by 30% and the `LOAD_CONST` instruction by 20%.\r\n\r\n\r\n```\r\n./bin/python3 -m pyperf timeit -w 3 --compare-to ../python-3.12/bin/python3 -s \"\r\ndef test():\r\n return 10000\r\n\" \"test()\"\r\n\r\n/python-3.12/bin/python3: ..................... 27.0 ns +- 0.3 ns\r\n/cpython/bin/python3: ..................... 25.0 ns +- 0.5 ns\r\nMean +- std dev: [/python-3.12/bin/python3] 27.0 ns +- 0.3 ns -\u003e [/cpython/bin/python3] 25.0 ns +- 0.5 ns: 1.08x faster\r\n\r\n./bin/python3 -m pyperf timeit -w 3 --compare-to ../python-3.12/bin/python3 -s \"\r\ndef test():\r\n return None\r\n\" \"test()\"\r\n\r\n/python-3.12/bin/python3: ..................... 27.2 ns +- 1.3 ns\r\n/cpython/bin/python3: ..................... 25.1 ns +- 0.6 ns\r\nMean +- std dev: [/python-3.12/bin/python3] 27.2 ns +- 1.3 ns -\u003e [/cpython/bin/python3] 25.1 ns +- 0.6 ns: 1.08x faster\r\n```\r\nFrom the microbenchmark that there is indeed a ~10% improvement (considering the interference of function calls, I think 10% should be there), which is not very high, but it should be an optimization without adverse effects.\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-101633\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/penguin-wwy","@type":"Person","name":"penguin-wwy"},"datePublished":"2023-02-07T06:53:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/101632/cpython/issues/101632"}
| 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:455ec2bb-ca4e-4822-5482-338ba77a944d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A79A:280881:256842:34CFE2:696A4B17 |
| html-safe-nonce | de0d3713c442e875efc2f58ca2ec70a64dafc482f9e3590f2b392353a4ed3b5e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzlBOjI4MDg4MToyNTY4NDI6MzRDRkUyOjY5NkE0QjE3IiwidmlzaXRvcl9pZCI6Ijg0MzgxNjkyNzc0MDE4NTM2NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 507e06f7dc79c424f3e0aa7021646dc01e8c20a20701bd919830fd611dd4b8cf |
| hovercard-subject-tag | issue:1573782759 |
| 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/101632/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f9223c54d8724466d6a3b619aab206b247a0aeb8c23079e3e51dca30301dc59c/python/cpython/issues/101632 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f9223c54d8724466d6a3b619aab206b247a0aeb8c23079e3e51dca30301dc59c/python/cpython/issues/101632 |
| og:image:alt | From the pystats doc (pystats-2023-02-05-python-5a2b984.md), I find that LOAD_CONST + RETURN_VALUE is a very high frequency (Because the default return of the function is None). Successors for LOAD... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | penguin-wwy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef |
| 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 | 63c426b30d262aba269ef14c40e3c817b384cd61 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width