Repository navigation
perf(editor): share token TextStyles between highlight segments (#1543) - #1686
Merged
Merged
Conversation
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.
Closes #1543.
_styleFromSegmentran(base ?? const TextStyle()).copyWith(...)for every segment, andsegmentsToTextSpanruns on every keystroke (patched segments while typing, and after each highlight pass). A theme has a handful of token looks, a document hundreds of tokens.(colour, has-colour, weight, font style), packed into one int, for the current base style. A new base (theme, font size) clears the cache; so does reaching 256 looks, so a pathological document cannot grow it.TextStyleinstance; segments with no colour, weight or style still getnull.Not measured: no editor scenario in the bench isolates span construction. The saving is the
copyWith,Colorand weight lookup per token, minus a hash lookup. Tests: shared instance for equal looks, base style and attributes preserved, a different base is not served stale styles, 600 distinct looks stay correct past the cache cap.