Skip to content

refactor: flush storage when compiler close#13395

Open
jerrykingxyz wants to merge 3 commits intomainfrom
jerry/storage
Open

refactor: flush storage when compiler close#13395
jerrykingxyz wants to merge 3 commits intomainfrom
jerry/storage

Conversation

@jerrykingxyz
Copy link
Contributor

@jerrykingxyz jerrykingxyz commented Mar 18, 2026

Summary

  1. Storage trait update fn trigger_save() -> Result<Receiver> to fn save() -> Result<()>, and provide a flush method to ensure the write operation is complete.
trait Storage {
  ...
- fn trigger_save(&self) -> Result<Receiver<Result<()>>>;
+ async fn save(&self) -> Result<()>;
+ async fn flush(&self);
}
  1. Js Compiler.close waits for rust compiler to close.
class Compiler {
  close(callback: (error?: Error | null) => void) {
    ...
-    this.#instance?.close();
-    callback();
+    const closePromise = this.#instance?.close();
+    if (closePromise) {
+      closePromise.then(() => callback(), callback);
+    } else {
+      callback();
+    }
    ...
  }
}

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings March 18, 2026 03:36
@github-actions github-actions bot added release: refactor team The issue/pr is created by the member of Rspack. labels Mar 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors persistent-cache storage writes to be queued asynchronously and introduces an explicit flush-on-close path so pending writes complete when the compiler shuts down.

Changes:

  • Update JS compiler shutdown to await the native close() promise when present.
  • Refactor rspack_storage::Storage from a oneshot-based “trigger_save” API to save() + flush(), and wire Cache::close() to flush pending writes.
  • Make filesystem transaction file moves tolerant of missing source files (with a new test).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/rspack/src/Compiler.ts Await native compiler close promise during shutdown.
packages/rspack-test-tools/src/case/cache.ts Remove explicit mode: 'production' from cache test options.
crates/rspack_storage/src/lib.rs Change storage trait to async save() + flush() API.
crates/rspack_storage/src/memory/mod.rs Implement no-op save()/flush() for in-memory storage.
crates/rspack_storage/src/filesystem/mod.rs Implement new storage API; enqueue DB writes and add flush().
crates/rspack_storage/src/filesystem/db/mod.rs Change DB save to enqueue-only and print on failures.
crates/rspack_storage/src/filesystem/scope_fs.rs Ignore NotFound on rename during move; add test case.
crates/rspack_storage/src/error.rs Adjust “not found” string matching heuristic.
crates/rspack_core/src/cache/mod.rs Add Cache::close() hook.
crates/rspack_core/src/cache/persistent/mod.rs Use new storage save() API and flush on cache close.
crates/rspack_core/src/cache/mixed.rs Delegate close() to the persistent cache.
crates/rspack_core/src/compiler/mod.rs Call cache.close().await during compiler close.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 826.2 KB 0
react-5k 2.7 MB 0
rome 984.2 KB 0
ui-components 2.3 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

📦 Binary Size-limit

Comparing 125f350 to fix(esm-lib): replace panics in get_module_chunk with Result-based error handling (#13396) by Fy

🎉 Size decreased by 9.50KB from 48.66MB to 48.65MB (⬇️0.02%)

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 18, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing jerry/storage (125f350) with main (816b725)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@jerrykingxyz jerrykingxyz force-pushed the jerry/storage branch 2 times, most recently from ce5da4a to 49e2c36 Compare March 18, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: refactor team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants