You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Semantic tokens: decode each answer once, for large files #2347
Gap 7 of #2334. #2338 fixes the rest of what that plan needs before semantic tokens drop "experimental"; this is one of the improvements that come after it.
Each pass decodes the answer again. Every highlighting pass decodes the whole token array, even when the answer hasn't changed (SemanticTokensData.highlight). It looks up the colors for each token, and on the PSI path it allocates an array as long as the document (LSPSemanticTokensHighlightVisitor, new LazyHighlightInfo[document.getTextLength()]).
The view provider keeps a map entry per character. For TEXT, TextMate and plugin file types without a language, the semantic tokens file view provider keeps one ConcurrentHashMap entry per character of every token, and each pass fills it again (LSPSemanticTokensFileViewProviderHelper).
The data is boxed. It arrives as List<Integer>, five integers per token.
Proposal
Decode once per answer, into sorted int[] arrays (start, end, key index), and keep them with the answer.
Reuse those arrays in every pass and in the view provider, with a binary search instead of a map entry per character.
Drop the array as long as the document.
Test
A benchmark-style test with a file of 50,000 tokens:
the time to decode it;
the allocations;
that a second pass without changes doesn't decode again.
Activity