You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf: replace O(n) name/varname list scan with O(1) dict lookup (#199)
* perf: replace O(n) name/varname list scan with O(1) dict lookup
_ConvertBytecodeToConcrete.add() used list.index() to find whether a
name or varname was already registered, making each lookup O(n) in the
number of names accumulated so far. For functions with many locals or
names this becomes a non-trivial cost on every HAS_LOCAL / HAS_NAME
instruction.
Replace the generic static add() method with two instance methods,
add_varname() and add_name(), each backed by a parallel dict
(varnames_map / names_map). Lookups are now O(1). The argnames
pre-population loop is also updated to go through add_varname() so the
map stays in sync.
We also move some more instruction validation checks from iteration to
insertion, which also contributes to the total uplift (~+3%).
Benchmark (round-trip test):
Baseline: 204.1 r/s (stdev 4.2)
This change: 221.3 r/s (stdev 2.9)
Uplift: +8.4%
* add changelog entry
* add tests
* add tests and rename
0 commit comments