Repository navigation
Commit ec3b950
gh-161145: Use _Py_find_first_nonascii in the tokenizer
Skip sequence of ASCII at once rather than one char per loop reusing
faster code from unicodeobject. Can't use the checking from stringlib
or unicodeobject fully because those assume copying/writing to an output
buffer which slows down this case. Line numbers are only needed for the
error message, so count them there. The function is exported because
test_peg_generator builds the tokenizer sources into an extension
module.
The check drops from about 0.9% of compile() time to about 0.1%
(perf record). CPU time per compile(), PGO+LTO, 20 paired runs on one
pinned core:
| Workload | main | this | runs faster |
|---|---:|---:|---:|
| typing.py | 6.72 ms | 1.2% faster | 17/20 |
| all top-level Lib/*.py | 241 ms | 0.7% faster | 17/20 |
| synthetic CJK literals | 4.32 ms | 1.3% faster | 16/20 |
_PyTokenizer_ensure_utf8 instructions during compile(), callgrind:
| File | main | this |
|---|---:|---:|
| typing.py | 1,811,154 | 132,909 |
| _pydatetime.py | 1,246,691 | 91,566 |
| test_email/test_contentmanager.py | 487,525 | 43,273 |
| synthetic Cyrillic literals | 5,825,590 | 3,832,223 |
| synthetic CJK literals | 3,450,590 | 2,479,019 |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 4a9b981 commit ec3b950
3 files changed
Lines changed: 28 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
237 | 244 | | |
238 | 245 | | |
239 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5047 | 5047 | | |
5048 | 5048 | | |
5049 | 5049 | | |
5050 | | - | |
5051 | | - | |
| 5050 | + | |
| 5051 | + | |
5052 | 5052 | | |
5053 | 5053 | | |
5054 | 5054 | | |
| |||
5188 | 5188 | | |
5189 | 5189 | | |
5190 | 5190 | | |
5191 | | - | |
5192 | | - | |
| 5191 | + | |
| 5192 | + | |
5193 | 5193 | | |
5194 | 5194 | | |
5195 | 5195 | | |
| |||
5348 | 5348 | | |
5349 | 5349 | | |
5350 | 5350 | | |
5351 | | - | |
| 5351 | + | |
| 5352 | + | |
5352 | 5353 | | |
5353 | 5354 | | |
5354 | 5355 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
257 | 258 | | |
258 | 259 | | |
259 | 260 | | |
260 | | - | |
261 | | - | |
| 261 | + | |
| 262 | + | |
262 | 263 | | |
263 | 264 | | |
264 | 265 | | |
265 | 266 | | |
266 | | - | |
267 | | - | |
| 267 | + | |
| 268 | + | |
268 | 269 | | |
269 | 270 | | |
270 | 271 | | |
| |||
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
324 | | - | |
325 | | - | |
| 325 | + | |
| 326 | + | |
326 | 327 | | |
327 | | - | |
| 328 | + | |
328 | 329 | | |
329 | 330 | | |
330 | 331 | | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | 332 | | |
336 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
337 | 341 | | |
338 | 342 | | |
339 | 343 | | |
| |||
0 commit comments