GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fold _BINARY_OP_SUBSCR_DICT for promoted frozendict constants · Issue #146381 · python/cpython

Fold _BINARY_OP_SUBSCR_DICT for promoted frozendict constants #146381

New issue
Copy link
New issue
Copy link
Closed
Closed
Fold _BINARY_OP_SUBSCR_DICT for promoted frozendict constants#146381
Copy link
Assignees
corona10
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetopic-JITtype-featureA feature request or enhancementA feature request or enhancement

Description

@corona10
corona10
opened on Mar 24, 2026
Issue body actions

This idea came up during a conversation with @Fidget-Spinner.

dct = frozendict(a=1)
def foo():
    dct['a'] # fold this to 1

When a frozendict is a promoted constant in the JIT, subscript lookups like dct['a'] should be foldable to the constant value at compile time. This would make frozendict lookups and match/case on frozendict significantly faster. If implemented, this optimization could create strong motivation for users to adopt frozendict in many more places, anywhere a dict is used as a read only lookup table, configuration mapping, or dispatch table.

Plan to start from REPLACE_OPCODE_IF_EVALUATES_PURE in optimizer_bytecodes.c and extend it to handle _BINARY_OP_SUBSCR_DICT for frozendict constant

cc @vstinner

Linked PRs

  • gh-146381: Fold frozendict(key=const, ...) calls to LOAD_CONST #146423
  • gh-146381: Constant-fold frozendict subscript lookups via REPLACE_OPCODE_IF_EVALUATES_PURE #146490
  • gh-146381: Constant fold local frozendict subscript lookups via recording #146564

Activity

  1. corona10
    self-assigned this
    on Mar 24, 2026
  2. corona10
    added
    topic-JIT
    performancePerformance or resource usagePerformance or resource usage
    on Mar 24, 2026
  3. StanFromIreland
    added
    type-featureA feature request or enhancementA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Mar 24, 2026
  4. corona10
    added 6 commits that reference this issue on Mar 25, 2026

    pythongh-146381: Fold frozendict(key=const, ...) calls to LOAD_CONST

    a09aef5

    pythongh-146381: Fold frozendict subscript via _BINARY_OP_SUBSCR_FROZ…

    77ad3d4

    pythongh-146381: Fold frozendict subscript via _BINARY_OP_SUBSCR_FROZ…

    098ac8b

    gh-146381: Constant-fold frozendict subscript lookups via REPLACE_OPC…

    5992238

    pythongh-146381: Constant fold local frozendict subscript lookups via…

    fc38b65

    pythongh-146381: Constant fold local frozendict subscript lookups via…

    170a3e0
  5. corona10 commented on Apr 4, 2026

    @corona10
    corona10
    on Apr 4, 2026
    MemberAuthor
    More actions

    Anyway global frozendict now become optimized.

  6. corona10
    closed this as completedon Apr 4, 2026
  7. clin1234
    added a commit that references this issue on Apr 16, 2026

    pythongh-146381: Constant-fold frozendict subscript lookups via REPLA…

    708b5dd
  8. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-146381: Constant-fold frozendict subscript lookups via REPLA…

    9f6238c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @corona10
    corona10

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetopic-JITtype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.