Skip to content

Fold _BINARY_OP_SUBSCR_DICT for promoted frozendict constants #146381

@corona10

Description

@corona10

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

Metadata

Metadata

Assignees

Labels

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

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions