Repository navigation
Fix the flaky language-server scan timing test at its cause - #152
Merged
Merged
Conversation
scanScripts lowercased the whole page to find tag names in any case. That
copied the page on every scan, which the language server runs per
keystroke, and most of the scan's time went to the copy. Unicode
lowercasing can also lengthen a string ("İ" becomes two characters), so
every offset after one pointed past the real text: a block after "İ" came
back with "</" on its end.
Tag names are now compared in place, in ASCII case, as an HTML parser
compares them.
Also adds a temporary probe that prints growth readings on CI for the
linear-time case that keeps failing there; it is removed before merge.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The "quote that never ends" check times one native search over 4 MB and 16 MB of text, so its growth is the CPU's cost of reading memory, which changes where an input stops fitting a cache. Where that is depends on the runner: a plain search read 5.2 to 5.6 at 1 MB against 4 MB on one CI runner, and this check read 12.2 to 16.6 at 4 MB against 16 MB on others, for linear work. It is now taken over the growth of a native search over the same two texts, which pays the same cost of reading them. A linear scan reads about 1 and a scan that rescans the text reads about 3.3 here; the bar is 2. The probe now also prints these ratios, with a quadratic control. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.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.
For the 1.0.0 release. Fixes the language-server timing test that failed four times in recent CI runs, plus a real offset bug found along the way. Independent of #151.
The flaky test
lsp/src/typescript-service.linear-time.test.tschecks that finding<script>blocks stays linear on half-typed markup. It times an input and one four times its size: linear work grows about 4×, quadratic about 16×, and the bar is 8.All four CI failures were the same case, "a quote that never ends" (
<script type="aaa…at 4 MB and 16 MB). Those runs read 12.2, 12.6, 16.5 and 16.6. It reads about 4 locally.Two things were wrong.
1. The scanner copied the page on every scan.
scanScriptslowercased the whole page to match tag names in any case. For this input that copy was most of the time measured, about 165 of 195 ns per KB, so the test was mostly timing a 16 MB allocation per run. The language server also runs this scan on keystrokes.2. The check timed reading memory against a fixed bar. With the copy gone, this case is one native search over the text. Its cost per character depends on whether the text fits the runner's CPU caches. On one CI runner a plain native search read 5.2 to 5.6 at 1 MB vs 4 MB, where linear should read 4. Cache sizes differ between runners, and an earlier fix that raised the sizes from 256 KB to 4 MB only moved the edge.
I couldn't reproduce the 12–16 readings on the runners I sampled; the old code read linear there too. So I can't say how much of each failure was the copy and how much was the cache. The test change below holds either way.
Changes
typescript-blocks.ts: tag names are compared in place, in ASCII case, as an HTML parser compares them. No copy of the page is made.typescript-service.linear-time.test.ts: the memory-bound case is now measured against a native search over the same two texts. Both pay the same cost of reading memory on any runner, so that cost cancels out. Linear work reads about 1, and the bar is 2. The other cases run JavaScript loops, have not flaked, and keep their bar of 8.Readings of the new check, at the test's sizes (4 MB vs 16 MB):
The real bug found along the way
Unicode lowercasing can make a string longer:
"İ".toLowerCase()is two characters. Positions found in the lowercased copy were used on the original page, so after everyİthey pointed one character further on. A TypeScript block after "İstanbul" came back with a stray</on its end, which then showed up in diagnostics and editor features. A new test fails without the fix. #151 fixes the same pattern in five other places.Verification
🤖 Generated with Claude Code