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
[mypyc] Precompute set literals for "in" ops against / iteration over set literals (#14409)
Towards mypyc/mypyc#726. (There's a Python
compatibility bug that needs to be fixed before the issue can be
closed.)
For example, the set literals here are now precomputed as frozensets at
module initialization.
```
x in {1, 2.0, "3"}
x not in {1, 2.0, "3"}
for _ in {1, 2.0, "3"}:
...
```
Set literal items supported:
- Anything supported by `irbuild.constant_fold.constant_fold_expr()`
- String and integer literals
- Final references to int/str values
- Certain int and str unary/binary ops that evaluate to a constant value
- `None`, `True`, and `False`
- Float, byte, and complex literals
- Tuple literals with only items listed above
**Results** (using gcc-9 on 64-bit Ubuntu)
Master @ 98cc165
running in_set
..........
interpreted: 0.495790s (avg of 5 iterations; stdev 6.8%)
compiled: 0.810029s (avg of 5 iterations; stdev 1.5%)
compiled is 0.612x faster
running set_literal_iteration
.........................................................................................
interpreted: 0.020255s (avg of 45 iterations; stdev 2.5%)
compiled: 0.016336s (avg of 45 iterations; stdev 1.8%)
compiled is 1.240x faster
This PR
running in_set
..........
interpreted: 0.502020s (avg of 5 iterations; stdev 1.1%)
compiled: 0.390281s (avg of 5 iterations; stdev 6.2%)
compiled is 1.286x faster
running set_literal_iteration
..............................................................................................
interpreted: 0.019917s (avg of 47 iterations; stdev 2.2%)
compiled: 0.007134s (avg of 47 iterations; stdev 2.6%)
compiled is 2.792x faster
Benchmarks can be found here: mypyc/mypyc-benchmarks#32
0 commit comments