FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-143732: Specialize `__setitem__` dunder method for `STORE_SUBSCR` by johng · Pull Request #156033 · python/cpython · GitHub

/ cpython Public

gh-143732: Specialize __setitem__ dunder method for STORE_SUBSCR - #156033

Closed
johng wants to merge 1 commit into
python:mainfrom
johng:gh-143732-store-subscr-py-dunder
Closed

gh-143732: Specialize __setitem__ dunder method for STORE_SUBSCR#156033
johng wants to merge 1 commit into
python:mainfrom
johng:gh-143732-store-subscr-py-dunder

Conversation

johng commented Aug 19, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

This is precursuor for JIT improvements but also results in standard interpreter improvements due to specializing the bytecode.

This improves performance by about 5% on linux and macos micro benchmark

import pyperf


class Grid:
    __slots__ = ("_cell",)

    def __setitem__(self, key, value):
        self._cell = value


def bench_store_subscr(loops):
    obj = Grid()
    range_it = range(loops)
    t0 = pyperf.perf_counter()
    for _ in range_it:
        # 20 stores per loop; keep in sync with inner_loops below
        obj[0] = 0; obj[0] = 0; obj[0] = 0; obj[0] = 0; obj[0] = 0
        obj[0] = 0; obj[0] = 0; obj[0] = 0; obj[0] = 0; obj[0] = 0
        obj[0] = 0; obj[0] = 0; obj[0] = 0; obj[0] = 0; obj[0] = 0
        obj[0] = 0; obj[0] = 0; obj[0] = 0; obj[0] = 0; obj[0] = 0
    return pyperf.perf_counter() - t0

if __name__ == "__main__":
    runner = pyperf.Runner()
    runner.metadata["description"] = "STORE_SUBSCR on an object with a Python __setitem__"
    runner.bench_time_func("store_subscr_py_dunder", bench_store_subscr, inner_loops=20)

This is precursuor for JIT improvements but also results in
standard improvements due to specializing the bytecode
johng force-pushed the gh-143732-store-subscr-py-dunder branch from 6ccc255 to 88e57eb Compare August 19, 2026 02:51
johng marked this pull request as ready for review August 19, 2026 03:01
johng requested a review from markshannon as a code owner August 19, 2026 03:01

Copy link
Copy Markdown
Member

This does not implement the specialization of STORE_SUBSCR for __setitem__ implemented in Python, as described in the issue. If the description in the issue is not clear, please ask for clarification (on the issue, not here)

johng commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Let me review this in more detail, thanks!

johng closed this Aug 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL