Skip to content

perf: cache resolved kit files settings in incremental manifest#3023

Open
inq wants to merge 2 commits into
sveltejs:masterfrom
inq:cache-kit-files-settings
Open

perf: cache resolved kit files settings in incremental manifest#3023
inq wants to merge 2 commits into
sveltejs:masterfrom
inq:cache-kit-files-settings

Conversation

@inq

@inq inq commented May 11, 2026

Copy link
Copy Markdown

loadKitFilesSettings does a dynamic import() of svelte.config.js on every --incremental run (~137 ms in my profile) just to read 4 paths under kit.files. This caches the resolved settings on the manifest, keyed by mtime+size. Manifest version bumped 3→4 to invalidate older caches.

Measured on a SvelteKit app, warm median: 2.13 s → 2.05 s (3 samples each). Loosely related to #1538.

@changeset-bot

changeset-bot Bot commented May 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dc2903f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-check Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jasonlyu123

jasonlyu123 commented May 11, 2026

Copy link
Copy Markdown
Member

I am not sure this makes sense. As long as any svelte files are updated, the config still needs to be loaded. The svelte.config.js also has configs used by the Svelte compiler. Caching it isn't as useful as you might think.

@inq

inq commented May 11, 2026

Copy link
Copy Markdown
Author

Hello! Thank you very much and Sorry for my bad English!

But In these cases, I think it can be meaningful enhancements:

  1. --incremental + no change -> index.ts#L370 only instantiate SvelteCheck (and configLoader) when filesNeedingDiagnostics.length > 0. So when nothing change, my loadKitFilesSettings is only code path that load svelte.config.js. This case happen a lot in monorepo pnpm typecheck — many packages have no change since last run.

  2. .svelte changed -> surprisingly it is slightly faster also! (median of 7 samples each)

version warm, no change warm, 1 file touched
svelte-check@4.4.6 2.15 s 2.11 s
this PR 2.05 s 1.99 s
  1. About compiler configconfigLoader and loadKitFilesSettings consume different parts of the config. We only cache kit.files paths, not preprocess/compilerOptions, so compiler always get fresh config.

  2. Savings scale with config sizesvelte-check@4.4.6 re-import full dep graph every run. With heavier config (added typescript, crypto, zlib, stream):

version warm, no change (heavy config)
svelte-check@4.4.6 2.21 s
this PR 2.04 s

So I think it would be positive in every case! But if you think the scope is too small, you can close this!

Thank you very much!

@jasonlyu123

Copy link
Copy Markdown
Member

One problem is that if the files config comes from an environment variable, the cache invalidation won't work. This can happen if people use the files config to have two sets of routes.

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.

2 participants