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: Reduce overhead for cache hits in specialized opcodes.
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Mark.Shannon Nosy List: Mark.Shannon, kj, lukasz.langa
Priority: normal Keywords: patch

Created on 2021-10-19 17:24 by Mark.Shannon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29092 merged Mark.Shannon, 2021-10-20 13:39
Messages (4)
msg404320 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-10-19 17:24
Every time we get a cache hit in, e.g. LOAD_ATTR_CACHED, we increment the saturating counting. Takes a dependent load and a store, as well as the shift. For fast instructions like BINARY_ADD_FLOAT, this represents a significant portion of work done in the instruction.

If we don't bother to record the hit, we reduce the overhead of fast, specialized instructions.

The cost is that may have re-optimize more often.
For those instructions with high hit-to-miss ratios, which is most, this be barely measurable.
The cost for type unstable and un-optimizable instruction shouldn't be much changed.

Initial experiments show ~1% speedup.
msg404423 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-10-20 10:43
Strong +1 from me.

Not to mention some instructions don't even need to read the _PyAdaptiveEntry apart from recording cache hits, so that's one more dependent load and store too.

Extremely cheap instructions off the top of my head:
- BINARY_SUBSCR
- LOAD_METHOD
- LOAD_GLOBAL
- LOAD_ATTR
msg404521 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-10-20 18:53
New changeset bc85eb7a4f16e9e2b6fb713be2466ebb132fd7f2 by Mark Shannon in branch 'main':
bpo-45527: Don't count cache hits, just misses. (GH-29092)
https://github.com/python/cpython/commit/bc85eb7a4f16e9e2b6fb713be2466ebb132fd7f2
msg404522 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-10-20 18:54
Thanks, Mark! ✨ 🍰 ✨
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89690
2021-10-20 18:54:51lukasz.langasetstatus: open -> closed
resolution: fixed
messages: + msg404522

stage: patch review -> resolved
2021-10-20 18:53:55lukasz.langasetnosy: + lukasz.langa
messages: + msg404521
2021-10-20 13:39:03Mark.Shannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request27361
2021-10-20 10:43:04kjsetmessages: + msg404423
2021-10-19 17:43:05Mark.Shannonsetnosy: + kj
2021-10-19 17:24:13Mark.Shannoncreate