Commit 35c2cc1
committed
perf(lua): O(1) decode glyph lookup instead of brute-forcing 4 lengths
The decoder tried substring lengths 4,3,2,1 at every position — up to 4 string
allocations + 4 table lookups per byte. A glyph's byte length is fixed by its
UTF-8 leading byte (self-synchronizing; lengths never overlap), so utf8_char_length
gives it in one step. One substring + one lookup per position now.
Measured (random data, this machine, before -> after):
decode 10MB: 7.77 -> 14.16 MB/s (1.8x)
decode 5MB: 5.49 -> 19.87 MB/s (3.6x)
decode 1MB: 9.62 -> 22.47 MB/s (2.3x)
Lua test/test still passes (correctness preserved).1 parent f09f945 commit 35c2cc1
1 file changed
Lines changed: 10 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
476 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
477 | 479 | | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
487 | 487 | | |
488 | 488 | | |
489 | 489 | | |
| |||
0 commit comments