Repository navigation
build(desktop): keep dist mtimes stable so unchanged embeds skip a full Rust rebuild - #566
Merged
Merged
Conversation
…ll Rust rebuild Vite rewrites every file under `dist/` on each build, so byte-identical outputs come out with brand-new mtimes. Tauri embeds `dist/` into the desktop crate (`tauri::generate_context!` -> `include_bytes!`), and cargo invalidates that crate whenever an embedded file's mtime changes. Measured on Windows: after a `vite build` with no source or frontend change, 380/380 dist files were byte-identical but 380/380 carried a new mtime, and the following no-op cargo build recompiled the crate for 130-133s. `npm run build` now runs `scripts/stabilize-dist-mtimes.mjs` after Vite and writes the recorded timestamp back for outputs whose bytes did not change. Timestamps only, never content, so a stale `dist/` cannot be embedded: a changed asset keeps its fresh mtime and the crate rebuilds as it must (verified: editing `index.html` moved exactly that one asset's mtime, 379 preserved). With the pass in place the no-op cargo build is 0.5s and stays there across runs. State lives in `desktop/node_modules/.cache` (gitignored); CI and fresh clones have none, so their first build behaves exactly as before.
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.
Problem
On Windows,
make install(or anytauri build) spent ~130s recompiling the desktop crate even when nothing changed at all — no source edit, no frontend edit, warmtarget/.Measured before the fix (
make installon a warm tree, no changes):Root cause
npm run buildruns Vite, and Vite rewrites every file underdesktop/dist/. Tauri embedsdist/into the desktop crate (tauri::generate_context!expands toinclude_bytes!for every asset), and cargo invalidates that crate whenever an embedded file's mtime changes.Measured on a no-op build:
So the desktop crate (lib + Thin-LTO link of the 35MB binary) was rebuilt on every install, even when every embedded byte was unchanged. Cargo stays clean (0.5s) when dist mtimes are left alone.
Fix
npm run buildnow runsscripts/stabilize-dist-mtimes.mjsright after Vite: for every output whose bytes are unchanged it writes the recorded timestamp back, so cargo sees an untouched frontend.dist/cannot be embedded. A changed asset keeps its fresh mtime and the crate rebuilds as it must.desktop/node_modules/.cache(gitignored). CI and fresh clones have none, so their first build behaves exactly as before; the pass is also a no-op whendist/is missing.utimesround-trips through seconds-as-double with ~400ns error, so the pass stores the timestamp actually on disk after writing and re-applies that value; pushing a value through the conversion a second time is a fixed point, which is what keeps cargo's fingerprint stable.Verification
Desktop JS checks on the merged tree:
tsc --noEmit,eslint "src/**/*.{ts,tsx}",eslint scripts/stabilize-dist-mtimes.mjs,stylelint,vitest run(877 tests) — all pass.Stabilizer behavior (worktree, real builds):
380 changed/new; runs 2-3:380 unchanged (mtime preserved)with byte-identical content and identical mtimes.desktop/index.html:379 unchanged, 1 changed/newand exactly that asset kept a fresh mtime — a real change still invalidates the crate.1 changed/new; the following no-op build:380 unchanged.End-to-end
make installon the merged tree (#3-#5are steady state, after the one-time normalization plus a genuine CLI rebuild caused by the new commit hash):Steady-state
make installtherefore drops from ~145s to ~13s; the remainder is npm (~6s), Vite (~1.7s), copies and the skills update. Further wins are available separately (skipnpm installon Windows when manifests are unchanged, avoid the network skills update on a plain install), but the desktop rebuild was ~90% of the cost.