Commit 63f8dc6
authored
perf(tokens): cache TokenizerCore per thread (#7547)
Rebuilding TokenizerCore on every `parse_one` call was ~6µs of wasted work;
the core's construction is purely a function of the Tokenizer subclass, so
caching it per (thread, class) is safe. Also drops two `list[T](...)`
subscripted-generic constructions that were pure type-annotation theatre,
and narrows `bit_strings` / `hex_strings` to `has_bit_strings` /
`has_hex_strings` bools since TokenizerCore only truthy-checks them.
ThreadLocalCache lives in tokens.py (not sqlglotc-compiled). Subclassing
threading.local inside a mypyc-compiled module causes a segfault because
mypyc's fixed-slot attribute access bypasses threading.local's per-thread
__dict__ swap, racing all threads on the same C slot.1 parent 5351ca1 commit 63f8dc6
2 files changed
Lines changed: 32 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
558 | 558 | | |
559 | 559 | | |
560 | 560 | | |
561 | | - | |
562 | | - | |
| 561 | + | |
| 562 | + | |
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
| |||
589 | 589 | | |
590 | 590 | | |
591 | 591 | | |
592 | | - | |
593 | | - | |
| 592 | + | |
| 593 | + | |
594 | 594 | | |
595 | 595 | | |
596 | 596 | | |
| |||
617 | 617 | | |
618 | 618 | | |
619 | 619 | | |
620 | | - | |
621 | | - | |
| 620 | + | |
| 621 | + | |
622 | 622 | | |
623 | 623 | | |
624 | 624 | | |
| |||
917 | 917 | | |
918 | 918 | | |
919 | 919 | | |
920 | | - | |
| 920 | + | |
921 | 921 | | |
922 | | - | |
| 922 | + | |
923 | 923 | | |
924 | 924 | | |
925 | 925 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
9 | 24 | | |
10 | 25 | | |
11 | 26 | | |
| |||
532 | 547 | | |
533 | 548 | | |
534 | 549 | | |
| 550 | + | |
| 551 | + | |
535 | 552 | | |
536 | 553 | | |
537 | 554 | | |
538 | 555 | | |
539 | 556 | | |
540 | 557 | | |
541 | 558 | | |
542 | | - | |
543 | 559 | | |
544 | 560 | | |
| 561 | + | |
545 | 562 | | |
546 | | - | |
| 563 | + | |
| 564 | + | |
547 | 565 | | |
548 | 566 | | |
549 | 567 | | |
| |||
559 | 577 | | |
560 | 578 | | |
561 | 579 | | |
562 | | - | |
563 | | - | |
| 580 | + | |
| 581 | + | |
564 | 582 | | |
565 | 583 | | |
566 | 584 | | |
| |||
0 commit comments