René's URL Explorer Experiment


Title: Call design for Tier 2 (uops) interpreter · Issue #106581 · python/cpython · GitHub

Open Graph Title: Call design for Tier 2 (uops) interpreter · Issue #106581 · python/cpython

X Title: Call design for Tier 2 (uops) interpreter · Issue #106581 · python/cpython

Description: (Maybe this is tentative enough that it still belongs in the faster-cpython/ideas tracker, but I hope we're close enough that we can hash it out here. CC @markshannon, @brandtbucher) (This is a WIP until I have looked a bit deeper into t...

Open Graph Description: (Maybe this is tentative enough that it still belongs in the faster-cpython/ideas tracker, but I hope we're close enough that we can hash it out here. CC @markshannon, @brandtbucher) (This is a WIP...

X Description: (Maybe this is tentative enough that it still belongs in the faster-cpython/ideas tracker, but I hope we're close enough that we can hash it out here. CC @markshannon, @brandtbucher) (This is a...

Opengraph URL: https://github.com/python/cpython/issues/106581

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Call design for Tier 2 (uops) interpreter","articleBody":"(Maybe this is tentative enough that it still belongs in the faster-cpython/ideas tracker, but I hope we're close enough that we can hash it out here. CC @markshannon, @brandtbucher)\r\n\r\n(This is a WIP until I have looked a bit deeper into this.)\r\n\r\nFirst order of business is splitting some of the CALL specializations into multiple ops satisfying the uop requirement: either use oparg and no cache entries, or don't use oparg and use at most one cache entry. For example, one of the more important ones, CALL_PY_EXACT_ARGS, uses both `oparg` (the number of arguments) and a cache entry (`func_version`). Splitting it into a guard and an action op is problematic: even discounting the possibility of encountering a bound method (i.e., assuming `method` is `NULL`), it contains the following `DEOPT` calls:\r\n```\r\n            // PyObject *callable = stack_pointer[-1-oparg];\r\n            DEOPT_IF(tstate-\u003einterp-\u003eeval_frame, CALL);\r\n            int argcount = oparg;\r\n            PyFunctionObject *func = (PyFunctionObject *)callable;\r\n            DEOPT_IF(!PyFunction_Check(callable), CALL);\r\n            PyFunctionObject *func = (PyFunctionObject *)callable;\r\n            DEOPT_IF(func-\u003efunc_version != func_version, CALL);\r\n            PyCodeObject *code = (PyCodeObject *)func-\u003efunc_code;\r\n            DEOPT_IF(code-\u003eco_argcount != argcount, CALL);\r\n            DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code-\u003eco_framesize), CALL);\r\n```\r\nIf we wanted to combine all this in a single guard op, that guard would require access to both `oparg` (to dig out `callable`) and `func_version`. The fundamental problem is that the callable, which needs to be prodded and poked for the guard to pass, is buried under the arguments, and we need to use `oparg` to know how deep it is buried.\r\n\r\nWhat if we somehow reversed this so that the callable is _on top of the stack_, after the arguments? We could arrange for this by adding a `COPY n+1` opcode just before the `CALL` opcode (or its specializations). In fact, this could even be a blessing in disguise, since now we would no longer need to push a `NULL` before the callable to reserve space for `self` -- instead, if the callable is found to be a bound method, its `self` can overwrite the original callable (below the arguments) and the function extracted from the bound method can overwrite the copy of the callable _above_ the arguments. This has the advantage of no longer needing to have a \"push `NULL`\" bit in several other opcodes (the `LOAD_GLOBAL` and `LOAD_ATTR` families -- we'll have to review the logic in `LOAD_ATTR` a bit more to make sure this can work).\r\n\r\n(Note that the key reason why the callable is buried below the arguments is a requirement about evaluation order in expressions -- the language reference requires that in the expression `F(X)` where `F` and `X` themselves are possibly complex expressions, `F` is evaluated before `X`.)\r\n\r\nComparing before and after, currently we have the following arrangement on the stack when `CALL n` or any of its specializations is reached:\r\n```\r\n    NULL\r\n    callable\r\n    arg[0]\r\n    arg[1]\r\n    ...\r\n    arg[n-1]\r\n```\r\nThis is obtained by e.g.\r\n```\r\n    PUSH_NULL\r\n    LOAD_FAST callable\r\n    \u003cload n args\u003e\r\n    CALL n\r\n```\r\nor\r\n```\r\n    LOAD_GLOBAL (NULL + callable)\r\n    \u003cload n args\u003e\r\n    CALL n\r\n```\r\nor\r\n```\r\n    LOAD_ATTR (NULL|self + callable)\r\n    \u003cload n args\u003e\r\n    CALL n\r\n```\r\nUnder my proposal the arrangement would change to\r\n```\r\n    callable\r\n    arg[0]\r\n    arg[1]\r\n    ...\r\n    arg[n-1]\r\n    callable\r\n```\r\nand it would be obtained by\r\n```\r\n    LOAD_FAST callable  /  LOAD_GLOBAL callable  /  LOAD_ATTR callable\r\n    \u003cload n args\u003e\r\n    COPY n+1\r\n    CALL n\r\n```\r\nIt would (perhaps) even be permissible for the guard to overwrite both copies of the callable if a method is detected, since it would change from\r\n```\r\n    self.func\r\n    \u003cn args\u003e\r\n    self.func\r\n```\r\nto\r\n```\r\n    self\r\n    \u003cn args\u003e\r\n    func\r\n```\r\nwhere we would be assured that `func` has type `PyFunctionObject *`. (However, I think we ought to have separate specializations for the two cases, since the transformation would also require bumping `oparg`.)\r\n\r\nThe runtime cost would be an extra `COPY` instruction before each `CALL`; however I think this might actually be simpler than the dynamic check for bound methods, at least when using copy-and-patch.\r\n\r\nAnother cost would be requiring extra specializations for some cases that currently dynamically decide between function and method; but again I think that with copy-and-patch that is probably worth it, given that we expect that dynamic check to always go the same way for a specific location.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-106707\n* gh-107760\n* gh-107793\n* gh-108067\n* gh-108380\n* gh-108462\n* gh-108493\n* gh-108895\n* gh-109338\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2023-07-10T04:34:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":27},"url":"https://github.com/106581/cpython/issues/106581"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:65c9b6c8-320a-10f1-7238-5a67ad973707
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8144:8D11F:20F43B3:2D31F6C:696ABEA3
html-safe-noncea84acd47fdcf65ef2d07483e982ef731c80218970168aacfef2485fa84713b29
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTQ0OjhEMTFGOjIwRjQzQjM6MkQzMUY2Qzo2OTZBQkVBMyIsInZpc2l0b3JfaWQiOiI4MzM2MzQ0NjAyMDMyOTE0MDgzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac2058027ca1cadc0dc4f2a05f98f7bdacdbbdcb757777d746aca58cd1fc7fd45e
hovercard-subject-tagissue:1795924058
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/106581/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d8417f5a997d7ef3ce06f1e6a060763e6d2a9556dbcee32c7d937929236cf25c/python/cpython/issues/106581
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d8417f5a997d7ef3ce06f1e6a060763e6d2a9556dbcee32c7d937929236cf25c/python/cpython/issues/106581
og:image:alt(Maybe this is tentative enough that it still belongs in the faster-cpython/ideas tracker, but I hope we're close enough that we can hash it out here. CC @markshannon, @brandtbucher) (This is a WIP...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamegvanrossum
hostnamegithub.com
expected-hostnamegithub.com
None46ce962e0e18113ea447391b6ace8b02d4d2861e57b4fbab3658698f73d8855b
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release30300f30bb3949de255e84a146706a3bdb5c19c9
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/106581#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F106581
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
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
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
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/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%2Fissues%2F106581
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%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/106581
Reloadhttps://github.com/python/cpython/issues/106581
Reloadhttps://github.com/python/cpython/issues/106581
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/106581
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k 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.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/106581
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 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/106581
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/106581
Call design for Tier 2 (uops) interpreterhttps://github.com/python/cpython/issues/106581#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
https://github.com/gvanrossum
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Jul 10, 2023https://github.com/python/cpython/issues/106581#issue-1795924058
@markshannonhttps://github.com/markshannon
@brandtbucherhttps://github.com/brandtbucher
gh-106581: Add 10 new opcodes by allowing assert(kwnames == NULL) #106707https://github.com/python/cpython/pull/106707
gh-106581: Split CALL_PY_EXACT_ARGS into uops #107760https://github.com/python/cpython/pull/107760
gh-106581: Start projecting through calls #107793https://github.com/python/cpython/pull/107793
gh-106581: Project through calls #108067https://github.com/python/cpython/pull/108067
gh-106581: Fix two bugs in the code generator's copy optimization #108380https://github.com/python/cpython/pull/108380
gh-106581: Split CALL_BOUND_METHOD_EXACT_ARGS into uops #108462https://github.com/python/cpython/pull/108462
GH-106581: Fix instrumentation in tier 2 #108493https://github.com/python/cpython/pull/108493
gh-106581: Support multiple uops pushing new values #108895https://github.com/python/cpython/pull/108895
gh-106581: Honor 'always_exits' in write_components() #109338https://github.com/python/cpython/pull/109338
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
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.