Repository navigation
Bound how long a code line's colouring takes by its length instead of a 500 ms time limit - #6769
Conversation
Shiki stops tokenizing a line after 500 ms by default and returns the rest of the line unstyled. The first line in a language also pays to compile the grammar's rules, and on a loaded machine that can exceed 500 ms, so the first block's line kept its tail in plain ink. On the macOS full-tier run 45044712114, the alias block's trailing comment came out uncoloured. The syntax entry now passes tokenizeTimeLimit: 0. test_code_colouring_keeps_each_blocks_words_and_annotations under leaf-dev suite flake --cpu-throttle 20 failed 6/6 copies before the change and passed 6/6 after it. Refs #6767
leaf-agent
left a comment
There was a problem hiding this comment.
Removing Shiki's per-line time limit makes a long line freeze the page for seconds on every machine. That is a bigger regression than the uncoloured tail it fixes, which appears only on a loaded machine. The inline comment has the measurements and three candidate fixes. Choosing among them means deciding how much main-thread time a line may take, so I'm leaving that decision here rather than pushing one.
…e-6767-syntax-time-limit # Conflicts: # browser/vendor/syntax.esm.js
|
This PR is waiting on a decision that the review's inline comment leaves open, so I haven't pushed a fix and it isn't landing. With The red |
…tokenizing it Shiki's 500 ms per-line time limit stays off, so a line under the cap is coloured to its end however loaded the machine is. A line at or past the cap, such as minified code, now comes back as one plain token instead of holding the main thread for seconds (a 102 KB line took 3.4 s uncapped and now takes about 15 ms). The maintainer chose the length cap over tokenizing in a worker (review on #6769). The cap is VS Code's. tests/runtime/syntax-line-length.test.mjs protects the bound: a line past the cap stays plain with its text intact, and the line after it is still coloured.
Shiki stops tokenizing a line after 500 ms by default (
tokenizeTimeLimit) and leaves the rest of that line unstyled. Because that limit is measured in time, whether a line gets fully coloured depends on how loaded the machine is. A language's first tokenized line also pays to compile the grammar rules it reaches. On a loaded machine that can exceed 500 ms, so the first block in a language ends its line in plain ink. That's thelanguage aliasesfailure in #6767: on the macOS full-tier run 45044712114, thejsblock was coloured first and lost its trailing// keep the sourcetoken, while thejavascriptblock below it kept it.tokenizein the syntax entry now bounds a line by its length instead:tokenizeTimeLimit: 0withtokenizeMaxLineLength: 20000(VS Code's cap). A shorter line is coloured to its end on any machine. A line at or past 20,000 characters, such as minified code, comes back as one plain token, with its text intact and the grammar state carried to the next line. The vendoredsyntax.esm.jsis rebuilt from the entry. A worker would remove the bound altogether, but the maintainer chose the length cap in review.Cost. A line just under the cap still takes about 0.8 s unloaded. Above the cap there's no wait: in Node, a 102 KB minified line takes 15 ms, against 518 ms on
mainand 3.4 s with no limit at all.Verification.
tests/runtime/syntax-line-length.test.mjs(new): a line past the cap stays plain with its text intact and the next line is still coloured. It fails with the cap set to 0 and passes with it.test_code_colouring_keeps_each_blocks_words_and_annotationsunderleaf-dev suite flake --copies 6 --workers 3 --cpu-throttle 20on Linux failed 6 of 6 onmainand passed 6 of 6 with the time limit off. The length cap doesn't affect that test's short lines.pnpm run check:browserpasses.#6767 also lists four other one-off macOS failures, which this PR doesn't touch.
Refs #6767 — automated triage