Skip to content

feat(loader): add in-memory loader chain cache - #15225

Draft
intellild wants to merge 14 commits into
codex/loader-chainfrom
codex/loader-chain-cache
Draft

feat(loader): add in-memory loader chain cache#15225
intellild wants to merge 14 commits into
codex/loader-chainfrom
codex/loader-chain-cache

Conversation

@intellild

@intellild intellild commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add Rule.use.cache and group adjacent cached loaders into a CacheChain while retaining the nested JavaScript/native execution chains from refactor(loader): schedule loader chains as execution units聽#15219
  • build the cache identity from the configured loader name, stable loader options, and either the loader package version or the resolved local loader file hash
  • introduce a process-wide LoaderCache registry backed by a global DashMap, with one shared LoaderCache instance per cache directory
  • encapsulate the private new_cache::MemoryCache storage behind LoaderCache::get/store; loader execution no longer sees cache facades or item storage
  • use <context>/node_modules/.cache/lodaer-cache as the hardcoded cache-directory identity; this version remains memory-only and does not write that directory

Example

module.exports = {
  cache: false,
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: require.resolve("example-loader"),
            options: { target: "modern" },
            cache: true
          }
        ]
      }
    ]
  }
};

For example, when an unrelated watched dependency triggers a rebuild but the input to this loader chain is unchanged, Rspack restores the cached chain result instead of running the loader again. Changing the resource content changes the input etag and executes the chain again. The loader cache is independent from the general compiler cache in this version.

For package loaders, the package name and version participate in the key. For non-package loaders, the resolved loader entry file is content-hashed. This first version intentionally does not include files imported or required by the loader in that file hash, and does not persist loader-chain entries.

Related links

Validation

  • cargo check -p rspack_loader_runner -p rspack_core -p rspack_binding_api -p rspack --all-targets --locked
  • cargo check -p rspack_core --lib --locked
  • cargo test -p rspack_loader_runner --locked (10 passed)
  • cargo check -p rspack_benchmark --bench benches --locked
  • targeted loaders/loader-chain-cache watch and incremental-watch cases (8 passed) with the general compiler cache disabled, including parallel cached loaders, dependency-triggered hits, source maps, additional data, and resource invalidation
  • binding development build and packages/rspack library build

Checklist

  • Tests updated.
  • Public option documentation updated.

by OpenAI Codex

@intellild intellild changed the title codex/loader chain cache feat(loader): add in-memory loader chain cache Aug 17, 2026
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.

1 participant