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
This idea came up during a conversation with @Fidget-Spinner.
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_PUREin optimizer_bytecodes.c and extend it to handle_BINARY_OP_SUBSCR_DICTfor frozendict constantcc @vstinner
Linked PRs