This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Inline bytecode caches
Type: performance Stage: patch review
Components: Interpreter Core Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: brandtbucher Nosy List: Mark.Shannon, brandtbucher, corona10, iritkatriel, neonene, pablogsal, penguin_wwy
Priority: deferred blocker Keywords: patch

Created on 2022-02-24 02:17 by brandtbucher, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 31543 merged brandtbucher, 2022-02-24 02:18
PR 31552 merged Mark.Shannon, 2022-02-24 11:21
PR 31575 closed Mark.Shannon, 2022-02-25 13:32
PR 31591 merged brandtbucher, 2022-02-25 23:20
PR 31618 merged Mark.Shannon, 2022-02-28 15:56
PR 31622 merged brandtbucher, 2022-02-28 20:08
PR 31640 merged brandtbucher, 2022-03-02 02:10
PR 31663 merged brandtbucher, 2022-03-03 18:55
PR 31664 merged brandtbucher, 2022-03-03 20:42
PR 31671 merged brandtbucher, 2022-03-03 22:36
PR 31709 merged brandtbucher, 2022-03-06 18:46
PR 31742 merged brandtbucher, 2022-03-08 00:26
PR 31780 merged brandtbucher, 2022-03-09 04:54
PR 31817 merged Mark.Shannon, 2022-03-11 10:16
PR 31888 merged brandtbucher, 2022-03-15 05:36
PR 31901 merged Mark.Shannon, 2022-03-15 12:27
PR 31968 open brandtbucher, 2022-03-17 20:15
PR 32099 open penguin_wwy, 2022-03-24 17:05
PR 32100 merged iritkatriel, 2022-03-24 17:40
PR 32205 merged brandtbucher, 2022-03-30 23:41
PR 32222 merged brandtbucher, 2022-03-31 23:00
Messages (29)
msg413875 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-02-24 02:17
...as discussed in https://github.com/faster-cpython/ideas/discussions/263.

My plan is for this initial PR to lay the groundwork, then to work on porting over the existing opcode caches one-by-one. Once that's done, we can clean up lots of the "old" machinery.
msg413901 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-02-24 10:55
We need to decide what to do about dis.

I don't think we should have a `show_cache` option, as the caches are meaningless junk without quickening (maybe we should drop the CACHE opcode, and just use zeroes).

Instead we should have a `show_quickened` option, to show the quickened form, which we need to make clear is very much implementation defined.
E.g. Cinder might show the machine code as well.

That way, we can present the cache information as extra data on the quickened form, rather than junk instructions.
msg413987 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-02-25 12:11
New changeset 0f41aac109c45aa468c432f798947c54d4178b3d by Brandt Bucher in branch 'main':
bpo-46841: Use *inline* caching for `BINARY_OP` (GH-31543)
https://github.com/python/cpython/commit/0f41aac109c45aa468c432f798947c54d4178b3d
msg413988 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-02-25 12:13
Making this a release blocker, as we really cannot leave this half finished for the release.

Shouldn't be a problem, as we'll have it done in a week or so.
msg414188 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-02-28 11:54
New changeset 424ecab494d538650ba34937cdd710094ccb2275 by Brandt Bucher in branch 'main':
bpo-46841: Use inline caching for `UNPACK_SEQUENCE` (GH-31591)
https://github.com/python/cpython/commit/424ecab494d538650ba34937cdd710094ccb2275
msg414194 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-02-28 12:56
New changeset 4558af5a8f8e56a9b0dc11f6e834c47e0fd05f9e by Mark Shannon in branch 'main':
bpo-46841: Move the cache for `LOAD_GLOBAL` inline. (GH-31575)
https://github.com/python/cpython/commit/4558af5a8f8e56a9b0dc11f6e834c47e0fd05f9e
msg414261 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-01 13:53
New changeset 7820a5897e7762df23bff1cbe749652130654a08 by Brandt Bucher in branch 'main':
bpo-46841: Use inline caching for `COMPARE_OP` (GH-31622)
https://github.com/python/cpython/commit/7820a5897e7762df23bff1cbe749652130654a08
msg414277 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-01 16:00
New changeset 3b0f1c5a710eff289dc44bec972dbaea353cc54f by Mark Shannon in branch 'main':
bpo-46841: Use inline cache for `BINARY_SUBSCR`. (GH-31618)
https://github.com/python/cpython/commit/3b0f1c5a710eff289dc44bec972dbaea353cc54f
msg414343 - (view) Author: neonene (neonene) * Date: 2022-03-02 13:18
UNPACK_SEQUENCE's slowdown is already filed?

https://speed.python.org/timeline/#/?exe=12&ben=unpack_sequence&env=4&revs=50&equid=off&quarts=on&extr=on

I hit the gap at 424ecab on Windows.
msg414349 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-03-02 13:49
This is marked as a release blocker so I am holding the alpha release on this. Is there anything we can do to unblock this issue?
msg414358 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-02 14:17
Is there some way to mark something as not blocking an alpha release, but blocking a beta release?

Everything is working at the moment, but not so efficiently.
msg414359 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-02 14:18
We should be done with this by early next week, if you can wait.
msg414364 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-03-02 15:02
> Is there some way to mark something as not blocking an alpha release, but blocking a beta release?

"Deferred blocker"
msg414371 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-02 16:10
Good to know, although "deferred blocker" is somewhat vague about when it is deferred until.

OOI, does it become a "blocker" again once you've done the alpha release, or what stops it being deferred past the beta or even the final release?
msg414372 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-02 16:18
It's not an UNPACK_SEQUENCE slowdown, it's a silly benchmark ;)

https://github.com/python/pyperformance/blob/main/pyperformance/data-files/benchmarks/bm_unpack_sequence/run_benchmark.py#L6

What I *think* is happening is that the inline cache takes the size of the function (in code units) from about 4800 to about 5200, crossing our threshold for quickening (currently set to 5000).

When we quicken in-place, there will be no need for a threshold and this issue will disappear. We should probably up the threshold for now, just to keep the charts looking good.
msg414378 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-03-02 16:53
> OOI, does it become a "blocker" again once you've done the alpha release, or what stops it being deferred past the beta or even the final release?

Check out the devguide:

https://devguide.python.org/triaging/#priority

> The issue will not hold up the next release, n. It will be promoted to a release blocker for the following release, n+1.

But in any case, I normally promote them to release blockers by hand and all of them become full blockers in the beta.
msg414391 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-03-02 23:40
> What I *think* is happening is that the inline cache takes the size of the function (in code units) from about 4800 to about 5200, crossing our threshold for quickening (currently set to 5000).

Yep, nailed it:

>>> len(list(dis.get_instructions(do_unpacking)))
4827
>>> len(list(dis.get_instructions(do_unpacking, show_caches=True)))
5251
>>> do_unpacking(1_000, range(10))
0.06478393300494645
>>> do_unpacking.__code__._co_quickened is None
True
msg414461 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-03-03 19:29
New changeset 127797f572cc7374192e415c44ea2e95b009d5ab by Brandt Bucher in branch 'main':
bpo-46841: Improve the failure stats for COMPARE_OP (GH-31663)
https://github.com/python/cpython/commit/127797f572cc7374192e415c44ea2e95b009d5ab
msg414490 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-03-03 23:31
New changeset 05a8bc1c944709e7468f157bd1b6032f368e43bf by Brandt Bucher in branch 'main':
bpo-46841: Use inline caching for attribute accesses (GH-31640)
https://github.com/python/cpython/commit/05a8bc1c944709e7468f157bd1b6032f368e43bf
msg414523 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-04 12:41
New changeset 586b24d3be1aec5d2568b070a249b4d75e608782 by Brandt Bucher in branch 'main':
bpo-46841: Fix error message hacks in `GET_AWAITABLE` (GH-31664)
https://github.com/python/cpython/commit/586b24d3be1aec5d2568b070a249b4d75e608782
msg414547 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-03-04 18:51
New changeset c4d2d57eefb1224a12e2e95e4508658dfbf6a7c9 by Brandt Bucher in branch 'main':
bpo-46841: Fix BINARY_OP's handling of inline caches (GH-31671)
https://github.com/python/cpython/commit/c4d2d57eefb1224a12e2e95e4508658dfbf6a7c9
msg414696 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-03-07 19:45
New changeset f193631387bfee99a812e39b05d5b7e6384b57f5 by Brandt Bucher in branch 'main':
bpo-46841: Use inline caching for calls (GH-31709)
https://github.com/python/cpython/commit/f193631387bfee99a812e39b05d5b7e6384b57f5
msg414763 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-08 15:53
New changeset 5498a61c7c25db6f9e76032aa9c5153d79e09889 by Brandt Bucher in branch 'main':
bpo-46841: Don't use an oparg counter for `STORE_SUBSCR` (GH-31742)
https://github.com/python/cpython/commit/5498a61c7c25db6f9e76032aa9c5153d79e09889
msg414955 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-03-12 00:31
New changeset a89c29fbcc7e7e85848499443d819c3fab68c78a by Brandt Bucher in branch 'main':
bpo-46841: Add a _Py_SET_OPCODE macro (GH-31780)
https://github.com/python/cpython/commit/a89c29fbcc7e7e85848499443d819c3fab68c78a
msg415307 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-03-16 00:08
New changeset 49e1e1e1bd59cac1855b1ef4dec05d649ebcd81a by Mark Shannon in branch 'main':
bpo-46841: Don't scan backwards in bytecode (GH-31901)
https://github.com/python/cpython/commit/49e1e1e1bd59cac1855b1ef4dec05d649ebcd81a
msg415676 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-21 11:11
New changeset 2bde6827ea4f136297b2d882480b981ff26262b6 by Brandt Bucher in branch 'main':
bpo-46841: Quicken code in-place (GH-31888)
https://github.com/python/cpython/commit/2bde6827ea4f136297b2d882480b981ff26262b6
msg415969 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-24 18:54
New changeset 2f49b97cc5426087b46515254b9a97a22ee8c807 by Irit Katriel in branch 'main':
bpo-46841: remove no-longer-used macro UPDATE_PREV_INSTR_OPARG (GH-32100)
https://github.com/python/cpython/commit/2f49b97cc5426087b46515254b9a97a22ee8c807
msg416482 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-04-01 10:42
New changeset bd2e47c8830d1b2869f2b4345945a5e0c3b4e3fb by Brandt Bucher in branch 'main':
bpo-46841: Avoid unnecessary allocations in code object comparisons (GH-32222)
https://github.com/python/cpython/commit/bd2e47c8830d1b2869f2b4345945a5e0c3b4e3fb
msg416483 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-04-01 11:29
New changeset ae9de82e321581e1906c6ef2a7ad83ab30ae3325 by Brandt Bucher in branch 'main':
bpo-46841: Use a `bytes` object for `_co_code_adaptive` (GH-32205)
https://github.com/python/cpython/commit/ae9de82e321581e1906c6ef2a7ad83ab30ae3325
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90997
2022-04-01 11:29:28Mark.Shannonsetmessages: + msg416483
2022-04-01 10:42:54Mark.Shannonsetmessages: + msg416482
2022-04-01 02:35:58corona10setnosy: + corona10
2022-03-31 23:00:09brandtbuchersetpull_requests: + pull_request30297
2022-03-30 23:41:50brandtbuchersetpull_requests: + pull_request30280
2022-03-24 18:54:44iritkatrielsetmessages: + msg415969
2022-03-24 17:40:04iritkatrielsetnosy: + iritkatriel
pull_requests: + pull_request30182
2022-03-24 17:05:02penguin_wwysetnosy: + penguin_wwy
pull_requests: + pull_request30181
2022-03-21 11:11:47Mark.Shannonsetmessages: + msg415676
2022-03-17 20:15:46brandtbuchersetpull_requests: + pull_request30057
2022-03-16 00:08:44brandtbuchersetmessages: + msg415307
2022-03-15 12:27:31Mark.Shannonsetpull_requests: + pull_request29996
2022-03-15 05:36:00brandtbuchersetpull_requests: + pull_request29986
2022-03-12 00:31:58brandtbuchersetmessages: + msg414955
2022-03-11 10:16:34Mark.Shannonsetpull_requests: + pull_request29915
2022-03-09 04:54:25brandtbuchersetpull_requests: + pull_request29886
2022-03-08 15:53:51Mark.Shannonsetmessages: + msg414763
2022-03-08 00:26:39brandtbuchersetpull_requests: + pull_request29859
2022-03-07 19:45:09brandtbuchersetmessages: + msg414696
2022-03-06 18:46:12brandtbuchersetpull_requests: + pull_request29828
2022-03-04 18:51:43brandtbuchersetmessages: + msg414547
2022-03-04 12:41:45Mark.Shannonsetmessages: + msg414523
2022-03-03 23:31:12brandtbuchersetmessages: + msg414490
2022-03-03 22:36:37brandtbuchersetpull_requests: + pull_request29791
2022-03-03 20:42:26brandtbuchersetpull_requests: + pull_request29783
2022-03-03 19:29:25brandtbuchersetmessages: + msg414461
2022-03-03 18:55:52brandtbuchersetpull_requests: + pull_request29782
2022-03-02 23:40:07brandtbuchersetmessages: + msg414391
2022-03-02 16:53:38pablogsalsetmessages: + msg414378
2022-03-02 16:18:32Mark.Shannonsetmessages: + msg414372
2022-03-02 16:10:54Mark.Shannonsetmessages: + msg414371
2022-03-02 15:02:24pablogsalsetpriority: release blocker -> deferred blocker
2022-03-02 15:02:20pablogsalsetmessages: + msg414364
2022-03-02 14:18:23Mark.Shannonsetmessages: + msg414359
2022-03-02 14:17:50Mark.Shannonsetmessages: + msg414358
2022-03-02 13:49:55pablogsalsetnosy: + pablogsal
messages: + msg414349
2022-03-02 13:18:41neonenesetnosy: + neonene
messages: + msg414343
2022-03-02 02:10:45brandtbuchersetpull_requests: + pull_request29761
2022-03-01 16:00:51Mark.Shannonsetmessages: + msg414277
2022-03-01 13:53:21Mark.Shannonsetmessages: + msg414261
2022-02-28 20:08:32brandtbuchersetpull_requests: + pull_request29747
2022-02-28 15:56:13Mark.Shannonsetpull_requests: + pull_request29743
2022-02-28 12:56:35Mark.Shannonsetmessages: + msg414194
2022-02-28 11:54:26Mark.Shannonsetmessages: + msg414188
2022-02-25 23:20:49brandtbuchersetpull_requests: + pull_request29714
2022-02-25 13:32:13Mark.Shannonsetpull_requests: + pull_request29697
2022-02-25 12:14:10Mark.Shannonsetpriority: normal -> release blocker
2022-02-25 12:13:57Mark.Shannonsetmessages: + msg413988
2022-02-25 12:11:41Mark.Shannonsetmessages: + msg413987
2022-02-24 11:21:27Mark.Shannonsetpull_requests: + pull_request29673
2022-02-24 10:55:27Mark.Shannonsetmessages: + msg413901
2022-02-24 02:18:54brandtbuchersetkeywords: + patch
pull_requests: + pull_request29666
2022-02-24 02:17:14brandtbuchercreate