-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
Open
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
This idea came up during a conversation with @Fidget-Spinner.
dct = frozendict(a=1)
def foo():
dct['a'] # fold this to 1When 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
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