Skip to content

perf: reduce ValidScopedCSSClass save latency on large themes#1181

Merged
aswamy merged 1 commit intomainfrom
perf/hoist-css-class-collection
Apr 23, 2026
Merged

perf: reduce ValidScopedCSSClass save latency on large themes#1181
aswamy merged 1 commit intomainfrom
perf/hoist-css-class-collection

Conversation

@aswamy
Copy link
Copy Markdown
Contributor

@aswamy aswamy commented Apr 17, 2026

Summary

Fixes the save-lag reported in #1179 and re-enables ValidScopedCSSClass in the recommended config (reversing the temporary opt-out from #1180).

What was happening

The check needed to know every CSS class declared anywhere in the theme to avoid false positives on CDN/utility classes. The language server was rebuilding that information from scratch on every save — re-reading and re-parsing every Liquid file with a stylesheet tag, even though the language server already holds the parsed syntax tree for every file in memory.

What this PR changes

Two architectural changes, no change to the check's output or public API:

  1. CSS class extraction is now a memoized derivation on the language server's document model — alongside schema and doc-definition extraction, following the same pattern. When a document changes, the model replaces the cached extraction automatically, so invalidation is implicit. The expensive parse work is shared across every consumer of a file's CSS classes and across every save within a session.

  2. Early exit for files with no stylesheet tag — cheap source-level scan avoids invoking the syntax-tree parser for files that cannot declare CSS classes.

Impact (measured on a 240-file theme)

  • First save after opening an editor: ~4.5s
  • Subsequent saves: ~4.5s → <100ms

Test plan

  • Install branch build in VS Code on a large theme (horizon should work)
  • First save latency lower than main; subsequent saves sub-second (see logs)
  • Editing a stylesheet tag, saving, and opening an ancestor shows the new class immediately

🤖 Generated with Claude Code

@aswamy aswamy force-pushed the perf/hoist-css-class-collection branch 2 times, most recently from ddd51bf to daeab3d Compare April 20, 2026 14:58
@aswamy aswamy marked this pull request as ready for review April 20, 2026 15:00
@aswamy aswamy requested a review from a team as a code owner April 20, 2026 15:00
Comment thread packages/theme-language-server-common/src/diagnostics/runChecks.ts Outdated
Comment thread packages/theme-check-common/src/utils/styles.ts Outdated
@aswamy aswamy force-pushed the perf/hoist-css-class-collection branch 2 times, most recently from 99126a6 to 0a2bb7c Compare April 20, 2026 18:12
@aswamy aswamy requested a review from graygilmore April 21, 2026 17:40
Comment thread packages/theme-check-common/src/utils/styles.ts
Comment thread packages/theme-check-common/src/utils/styles.ts Outdated
Comment thread packages/theme-language-server-common/src/diagnostics/runChecks.ts Outdated
Moves per-file CSS class extraction onto the language server's
AugmentedLiquidSourceCode so it is memoized per file version and
invalidated automatically when a document changes. Eliminates the
full-theme rescan that ran on every save. Also skips syntax-tree
parsing for Liquid files with no stylesheet tag, cutting first-save
and CLI-run costs.

Re-enables ValidScopedCSSClass in the recommended config, reversing
the temporary opt-out from #1180.

Fixes #1179.
@aswamy aswamy force-pushed the perf/hoist-css-class-collection branch from 0a2bb7c to 597a3c5 Compare April 22, 2026 16:16
@aswamy aswamy merged commit 892683d into main Apr 23, 2026
8 checks passed
@aswamy aswamy deleted the perf/hoist-css-class-collection branch April 23, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants