Repository navigation
Description
Follow-up to #19204 (git changes in the editor gutter), from the round-2 review discussion.
Background
The gutter uses Ace's ext/diff provider, which works in two phases: it aligns lines, then refines every changed block character by character for inner highlights. The gutter only reads line ranges, so the second phase is wasted work. It is also quadratic in the characters of the block: unbounded, a 309-line replacement takes about 4 seconds on raw text, and the 250ms budget is used up by any replaced block of roughly 100 lines or more.
Since 6b05734 the gutter trims the lines common to both ends before diffing, and re-runs a result that used the whole budget on one-character per-line tokens (identical lines get identical tokens), where the refinement is negligible. That re-run is a fallback only, so a large replaced block still costs about 250ms plus the re-run on every typing pause, and a fully replaced block of ~800+ lines still gets no markers because the token alignment itself exceeds the budget.
Proposal
Feed the provider tokens from the start instead of raw lines. Measured gains:
- a large replaced block would cost tens of milliseconds per pause rather than ~250ms plus the re-run;
- a result that uses the whole budget could then only be a slow alignment, so the timeout rule loses its ambiguity.
What to evaluate
Tokens change three of the provider's heuristics, which today only apply on the fallback path and would apply to every edit:
- Indentation-based placement.
LineSequence.getBoundaryScoreuses the lines' indentation to decide where an ambiguous chunk sits (a blank line or closing brace that could be attributed to two places). Tokens carry no indentation. - Short-line joining.
removeVeryShortMatchingLinesBetweenDiffsmerges two changes separated by one unchanged line of at most four non-whitespace characters. One-character tokens make every line look short. - Length-weighted alignment. The dynamic-programming pass (under 1,700 total lines) scores matches by
1 + log(1 + length). Uniform tokens flatten that.
Possible middle grounds: prefix tokens with the original indentation (measured at about 10x the refinement cost of bare tokens, but still far below raw text), or pad tokens to reflect the original line's non-whitespace length up to the heuristic's threshold. Each needs its own comparison against raw-text output over a set of real files, and against what git diff shows for the same edits.
A Node harness that loads ace-uncompressed.js, ext-diff-uncompressed.js and git_diff_gutter.js in a vm context (set window to the context, call require("ace/lib/dom").useStrictCSP(true) before loading ext-diff) is a convenient way to compare chunk output and timings without the IDE.
Activity