Repository navigation
perf(db): cache schema types between builds - #947
Merged
Merged
Conversation
Generating hub/db/schema.d.mts runs tsc on every nuxt dev start, even when the schema did not change. The declarations are now cached in <buildDir>/cache/nuxthub/db (Nuxt keeps it when it clears the build dir) together with a hash of their inputs: the files both builds read, including type-only imports, the versions of the packages they import, the aliases they use and the TypeScript version. When the hash matches, only schema.mjs is built and the cached declarations are copied back. Amp-Thread-ID: https://ampcode.com/threads/T-01a17c6c-89ae-70c3-904f-443b6c55256f Co-authored-by: Sébastien Chopin <atinux@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
playground | 7cd0640 | Commit Preview URL Branch Preview URL |
Oct 27 2026, 08:50 AM |
commit: |
Merged
This branch was successfully deployed
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.
An alternative to #946 for comparison. Written by an AI agent (Amp) on behalf of @atinux.
Each
nuxt devstart runstscto generatehub/db/schema.d.mts, even when the schema has not changed. This PR caches the declarations instead of movingtscto the background:After a full build,
schema.d.mtsis copied to<buildDir>/cache/nuxthub/db/. A hash of its inputs is stored next to it. Nuxt keepscache/when it clears the build directory ondevandprepare.The hash covers:
$type<Meta>()interfacedrizzle-orm)Only the used aliases are hashed, because Nuxt aliases such as
#app-manifestchange on everyprepare/build.When the hash matches, only
schema.mjsis built and the cached declarations are copied back. Otherwise the build runs as before.The change is contained in
buildDatabaseSchema, sodev,prepare,build,nuxt dband the schema watcher use the same path. There is no background work and no extra CPU, and a schema edit refreshes the types as fast as before.Numbers
Playground (SQLite, 3 schema files), Node 24, 4-CPU Amp orb. Each round deletes
playground/.nuxt, then startsnuxi dev playgroundtwice:tsclikemain..nuxt, which is the usual restart. This PR hits the cache.The rounds alternate between the three branches. Each value is the median of 5 rounds.
typesphase.nuxt)typesphase"First HTML" is measured from process start until
GET /returns 200. "CPU" is user plus system time of thenuxiprocess tree at that moment. The orb is noisy: single runs of the same branch differ by up to about 30%, so read the medians as trends.On the second start, #946 and this PR cut the
typesphase by the same amount. #946 still runstscin the background during startup, while this PR skips it. On the first start, #946 is ahead on "Ready in" because this PR still runstscin the foreground.buildDatabaseSchemaalone, on a small schema: 1.5 s without the cache, about 7 ms with it, and 0.7 s to rebuild after a change to a file imported only for its types.Checks
pnpm lint,vue-tsc --noEmitandpnpm testpass locally (167 passed, 3 skipped).