Skip to content

perf(theme): cache the hash of token colours instead of rehashing per build - #1401

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1353-cache-token-colors-hash
Oct 10, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1353-cache-token-colors-hash

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Closes #1353

Problem

QueryaCodeEditor._syncThemeIfNeeded ran Object.hashAll(queryaTheme.tokenColors) on every build, and SyntaxHighlightService.createPair did the same for its cache key. An imported VS Code theme has 100-300+ rules, so every cursor blink or ancestor rebuild iterated them all.

Change

  • QueryaTheme.tokenColorsHash: computed once per tokenColors list and cached in an Expando keyed by the list.
  • Both call sites use it.

Why an Expando keyed by the list

QueryaTheme has a const constructor (the defaults are const), so a late final field is not allowed. And QueryaTheme.lerp / copyWith create a new theme per animation frame that reuses the same tokenColors list, so a per-theme cache would be recomputed every frame; keyed by the list it is computed once.

Tests

querya_theme_token_colors_hash_test.dart: equals Object.hashAll, stable, shared across copyWith / lerp, differs for different rules, empty-list hash for the defaults.

Not run locally; CI is the check.

QueryaCodeEditor and SyntaxHighlightService hashed every TokenColorRule
on each call. The hash is now computed once per tokenColors list (an
Expando keyed by the list, so lerp/copyWith themes sharing it reuse it).
Closes #1353.
@github-actions github-actions Bot added theme Theming, colors, VS Code themes editor Code/SQL editor performance Theme parser epic label: performance P3 Low priority / Polish & Enhancements labels Oct 10, 2026
@github-actions github-actions Bot added this to the Theme system milestone Oct 10, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit 48e92a0 into dev Oct 10, 2026
13 checks passed
@ZhuchkaTriplesix
ZhuchkaTriplesix deleted the issue/1353-cache-token-colors-hash branch October 11, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

editor Code/SQL editor P3 Low priority / Polish & Enhancements performance Theme parser epic label: performance theme Theming, colors, VS Code themes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant