perf: use lookup table in splitIntoPotentialTokens#240
Conversation
Replace multi-comparison chains with a Uint8Array bitmask lookup per character. Phase 1 checked 4 conditions (cc !== 10/59/123/125) and phase 2 checked 6 conditions (cc === 59/32/123/125/13/9) on every character. The lookup table reduces both to a single indexed read plus one bitwise AND. Benchmark results (ops/s, higher is better): splitIntoPotentialTokens fixture: 533 → 574 (+7.7%) splitIntoPotentialTokens big: 392 → 474 (+20.9%) original-source streamChunks(): 904 → 983 (+8.7%) original-source streamChunks(big): 334 → 419 (+25.4%) realistic cold sourceAndMap(): 864 → 901 (+4.3%) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 04b8a57 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merging this PR will improve performance by 23.21%
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #240 +/- ##
=======================================
Coverage 97.58% 97.59%
=======================================
Files 25 25
Lines 2069 2076 +7
Branches 668 664 -4
=======================================
+ Hits 2019 2026 +7
Misses 47 47
Partials 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
splitIntoPotentialTokenswith a 128-byteUint8Arraybitmask lookup tablecc !== 10/59/123/125) and phase 2 checked 6 conditions (cc === 59/32/123/125/13/9) per character — now both are a single indexed read + bitwise ANDBenchmark results (ops/s, higher is better)
No regressions observed. All 89,869 tests pass.
Test plan
yarn lintpassesnpx jest --no-coverage— 89,869 tests passnpm run benchmark🤖 Generated with Claude Code