Skip to content

Persistent-cache snapshot work scales with unchanged Tailwind file dependencies during HMR #14765

Description

@matthewdavis-oai

Problem

While profiling a one-file TSX HMR edit in a large Rsbuild/Rspack application, the TSX transform itself takes about 28 ms, but a warm rebuild still spends roughly 0.4--0.8 s in persistent-cache snapshot/metadata work. The compilation has thousands of Tailwind-watched source files. Making the persistent cache read-only consistently removes about 0.7--0.8 s from the web rebuild, so this is synchronous rebuild work rather than background cache writes.

Findings

  1. Compilation::{context,missing,build}_dependencies() appended self.file_dependencies to their respective added iterators. This made every compilation-level file dependency also look like an added context, missing, and build dependency. The chains must append self.context_dependencies, self.missing_dependencies, and self.build_dependencies respectively.
  2. Loaders such as Tailwind can remove and re-add thousands of unchanged watched files during a rebuild. Forwarding every re-added file to save_snapshot is expensive, but filtering that set only by compilation.modified_files is not generally safe: Watching.invalidate(), directory-only watcher provenance, or a loader/plugin mutating an already-tracked file during compilation can omit the exact file and allow a later cold-cache start to accept stale output.

Current status

The compilation dependency-delta correctness fix and focused disjoint-iterator regression are stacked in #14772 (601ac45): context, missing, and build dependencies now append only to their corresponding added iterators. The regression is compilation_level_dependencies_stay_in_their_own_added_iterators.

The more aggressive re-added-file snapshot filter is deliberately not included. The remaining work for this issue is to establish a safe snapshot-provenance contract and measure a correctness-preserving filter. Directory, missing, build, added, and removed dependency semantics must remain intact.

The earlier standalone patch/digest and its snapshot regression are historical experiments, not a supported patch to apply. This snapshot investigation is independent of the precise CSS-HMR work in #14682: reducing compiler-side metadata work still matters when an edited TSX produces identical CSS.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions