Title: Issue · GitHub
Open Graph Title: Issue · python/cpython
X Title: Issue · python/cpython
Description: The Python programming language. Contribute to python/cpython development by creating an account on GitHub.
Open Graph Description: The Python programming language. Contribute to python/cpython development by creating an account on GitHub.
X Description: The Python programming language. Contribute to python/cpython development by creating an account on GitHub.
Opengraph URL: https://github.com/python/cpython
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Store both function and code object in the function version cache","articleBody":"(Copied from https://github.com/faster-cpython/ideas/issues/665.)\r\n\r\nThe idea here is to avoid function version cache misses for generator expressions. (See https://github.com/faster-cpython/ideas/issues/664#issuecomment-2000948111.)\r\n\r\nWe have a complicated mechanism to reset the function version whenever `__code__`, `__defaults__` and a few other critical attributes are mutated. (BTW: nothing is affected by changes to `__annotations__`, and yet that is also considered critical; I will fix this.)\r\n\r\nWhy not instead just reset the function version to zero and stick to that? We then guarantee that the function version is either zero or matches the code object version.\r\n\r\nNothing changes for specialization except that `_PyFunction_GetVersionForCurrentState()` returns 0 for mutated functions. This is unlikely to affect any benchmark or other perf-critical real-world code.\r\n\r\nThe function version cache will double in size, and store both the function and the code object. When a function is deallocated or its version is reset to zero, it evicts itself from the cache, but keeps the code object. Code objects remove themselves from the cache when deallocated (and probably also evict the function object).\r\n\r\nFor Tier 2, when generating `_PUSH_FRAME` or `_POP_FRAME`, we can handle the case where the function version maps to a pair `(NULL, some_code_object)` -- we store `NULL` in the operand, but we use `some_code_object` to trace through. Globals removal will no longer work (boo hoo), but at least we still have a trace. Presumably at least *some* generator expressions don't use globals (they can still use builtins, which can be reached without the function object).\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-117028\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2024-03-19T21:27:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/117045/cpython/issues/117045"}
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:1a03492c-ff25-1cd0-d8b0-6f3586b8e071 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B8CA:3F5325:12F07E4:1B97642:6A5618F9 |
| html-safe-nonce | 56c0a7218848658dc88d56fc558e6bdd8b44dee79e7f019fccdf997f87b828e3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOENBOjNGNTMyNToxMkYwN0U0OjFCOTc2NDI6NkE1NjE4RjkiLCJ2aXNpdG9yX2lkIjoiOTE4NDM0NjQ0OTY2Mzg5MTcwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ccd81c541b7bbc845fd5c6fce675b7e7fa0604289ebc8bde273540735d91e808 |
| hovercard-subject-tag | repository:81598961 |
| 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/python/cpython/issues/117045 |
| twitter:image | https://opengraph.githubassets.com/c5acac5493f0d752686766348996e0aa106ec2f820a3013d7052b32d6594b3d9/python/cpython |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c5acac5493f0d752686766348996e0aa106ec2f820a3013d7052b32d6594b3d9/python/cpython |
| og:image:alt | The Python programming language. Contribute to python/cpython development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | f4368738fc918fecd9b3958f6b49218bbe60d4185f38e72e3954e11f1ad0213a |
| turbo-cache-control | no-cache |
| 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 | b76b9cc70d30da50674184c9c66c56423fd0b93c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width