Repository navigation
perf(lang): optimize unicode script detection with binary search - #1349
Merged
NandhaKishorM merged 1 commit intoOct 24, 2026
Merged
NandhaKishorM merged 1 commit into
NandhaKishorM merged 1 commit into
Conversation
NandhaKishorM
added a commit
that referenced
this pull request
Oct 24, 2026
33 PRs. Server hardening (#1331, #1332, #1333), TypeScript parity (#1330, #1336, #1337, #1338, #1339, #1340, #1341, #1342, #1343), fail-closed input handling in evals and the integrations (#1317, #1318, #1319, #1320, #1321, #1322, #1326, #1335), exact and faster script detection (#1334, #1349), JVM and .NET resource handling (#1327, #1328, #1329, #1346), port goldens and clipping (#1324 excluded, #1325, #1344, #1345), CI (#1323, #1347, #1348). Verified before tagging: all 92 suites pass, 610 tests. ruff clean on both lists. laya-ts 1247 tests across 44 files, tsc --noEmit clean. Version agrees across pyproject.toml, laya.__version__ and nix/package.nix. README carries 0.4.15 only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
in
laya/lang.py:_SCRIPT_RANGESinto sorted interval arrays at module import (_STARTS,_ENDS,_SCRIPTS)._script_countsand_script_ofwithbisect.bisect_right.cp < 0x0250) untouched.Why
in
_script_countsand_script_of, detecting non-ASCII scripts previously iterated through 25 script definitions across 39 disjoint intervals, evaluatingany(lo <= cp <= hi for lo, hi in ranges)per character. for scripts defined near the end of the list (like Han, Hiragana, Katakana, Hangul), this evaluated up to 25 generator expressions per character.replacing linear scans with binary search over sorted static intervals finds the matching script in at most 5 comparisons in C ($O(\log K)$ vs $O(K)$ ), with 0 mismatches verified across all 1,114,112 Unicode codepoints (
0to0x10FFFF).tested on
_script_counts(isolated 3,000 iterations):tested on
Router.route_batchbefore and after:How it was verified
all passed: