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
perf(editor): Flyweight TextStyle cache in syntax_highlight_isolate to eliminate hundreds of copyWith allocations #1543
In segmentsToTextSpan and _styleFromSegment (lib/core/editor/syntax_highlight_isolate.dart), (base ?? const TextStyle()).copyWith(...) is called on every single token segment, along with looping through FontWeight.values and allocating Color objects.
For a 500-token SQL query, this creates 500 distinct TextStyle instances on every syntax re-span, even though modern editor themes only contain 6-10 unique styling combinations.
Solution
Implement a static/memoized Flyweight style cache keyed by composite style ID: (colorArgb | (fontWeight << 32) | (fontStyle << 40)).
Reuse existing TextStyle references for identical token styles across the entire document.
Benefits
Eliminates hundreds of TextStyle and Color allocations per highlight pass.
Faster text span construction during interactive editing.
Fixed on dev by c12e383: perf(editor): share token TextStyles between segments instead of copyWith per token (#1543) (#1686). It reaches main with the next dev to main merge (closed after checking the code and its tests).
Activity
perf(editor): share token TextStyles between segments instead of copy…
ZhuchkaTriplesix commentedon Oct 25, 2026
Fixed on dev by c12e383: perf(editor): share token TextStyles between segments instead of copyWith per token (#1543) (#1686). It reaches main with the next dev to main merge (closed after checking the code and its tests).