mypy
84a20bdb - [mypyc] Specialize `s[i] == 'x'` to a codepoint int compare (#21579)

Commit
19 days ago
[mypyc] Specialize `s[i] == 'x'` to a codepoint int compare (#21579) 7th PR of #21418 Lowers `s[i] == 'x'` (and the symmetric `==` / `!=` forms) down to a bounds-checked codepoint read + int compare, instead of `CPyStr_GetItem` + `CPyStr_EqualLiteral` which (may) allocate a 1-character `PyUnicode` per iteration. No annotations are required for this optimization. On microbenchmarks (1-compare-per-iter hot loop, ~2.5M-codepoint SQL-like string) the comparison is ~3.6x times faster. <br /> Some follow up optimizations that might be worth it I can work on: - In operator e.g `s[i] in ('a', 'b', 'c')` --> Fuse to one check with N int comparisons - Comparison operators e.g `s[i] < 'x'` --> Need to expand the op set - `s[i] == s[j]` --> Need drop the literal-only guard
Author
Parents
Loading