Avoid unnecessary parser lookahead for operators#25290
Conversation
|
Merging this PR will improve performance by 10.75%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | ty_micro[complex_constrained_attributes_1] |
74.6 ms | 70.6 ms | +5.69% |
| ⚡ | Simulation | ty_micro[many_tuple_assignments] |
65.8 ms | 62 ms | +5.99% |
| ⚡ | Simulation | ty_micro[complex_constrained_attributes_2] |
74.4 ms | 70 ms | +6.17% |
| ⚡ | Simulation | ty_micro[pandas_tdd] |
255.3 ms | 238.9 ms | +6.89% |
| ⚡ | Simulation | ty_micro[complex_constrained_attributes_3] |
80.8 ms | 76.9 ms | +5.03% |
| ⚡ | Simulation | ty_micro[many_tuple_assignments] |
74.4 ms | 70.1 ms | +6.18% |
| ⚡ | Simulation | ty_micro[gradual_vararg_call] |
74.9 ms | 70.7 ms | +6.03% |
| ⚡ | Simulation | ty_micro[many_enum_members] |
100.1 ms | 95.3 ms | +4.99% |
| ⚡ | Simulation | ty_micro[vararg_parameter_type_accumulation] |
64.1 ms | 60.4 ms | +6.17% |
| ⚡ | Simulation | ty_micro[many_enum_members_2] |
95.9 ms | 91.5 ms | +4.88% |
| ⚡ | Simulation | ty_micro[very_large_tuple] |
76.7 ms | 72.3 ms | +6.05% |
| ⚡ | Simulation | ty_micro[many_string_assignments] |
85 ms | 81 ms | +5.02% |
| ⚡ | Simulation | parser[large/dataset.py] |
4.7 ms | 3.6 ms | +30.44% |
| ⚡ | Simulation | parser[numpy/ctypeslib.py] |
883.8 µs | 713.6 µs | +23.85% |
| ⚡ | Simulation | parser[numpy/globals.py] |
103.7 µs | 90.4 µs | +14.77% |
| ⚡ | Simulation | parser[pydantic/types.py] |
1.8 ms | 1.4 ms | +27.42% |
| ⚡ | Simulation | parser[unicode/pypinyin.py] |
308.6 µs | 251.3 µs | +22.78% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing charlie/parser-bench-delimiter-depth (9764ee1) with main (6cbd59b)
|
I would do another /goal round looking at the buffers that peek() is using. My mind's eye has loading whole cache lines when possible so it's only doing memory fetch or OS calls when absolutely needed. |
## Summary We only need to peek ahead two tokens if the first token is `not` or `in`. We can avoid the `peek` in the majority of cases, which apparently speeds up the parser by 20-30%.
## Summary We only need to peek ahead two tokens if the first token is `not` or `in`. We can avoid the `peek` in the majority of cases, which apparently speeds up the parser by 20-30%.
Summary
We only need to peek ahead two tokens if the first token is
notorin. We can avoid thepeekin the majority of cases, which apparently speeds up the parser by 20-30%.