perf: avoid copying complete asset buffers - #71
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9cdffc250a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /** @type {{ _setBuf(buffer: Buffer): void }} */ ( | ||
| /** @type {unknown} */ (this) | ||
| )._setBuf(buffer); |
There was a problem hiding this comment.
Preserve write-buffer snapshot semantics
When a plugin or other caller reuses or mutates a Buffer after a synchronous write returns (or after an asynchronous write's callback), _setBuf(buffer) leaves the file backed by that same mutable storage. A later buffer.fill() therefore silently changes the bytes served by the middleware without another filesystem write, metadata update, or watcher event; the previous Node.write path copied the bytes. Because this hook applies to every complete write rather than only buffers whose ownership Rspack can guarantee, the filesystem must preserve the normal post-write snapshot semantics.
Useful? React with 👍 / 👎.
Reuse complete Rspack asset buffers in the default memfs output filesystem, avoiding a second copy and unused growth capacity. Pin memfs/fs-core to 4.79.0 because this uses the private
_setBufAPI; callers must not mutate buffers after complete writes.In a real Rspack + middleware benchmark (6 processes per variant, 100 rebuilds each), median results were:
Measured on Apple M5 Max, Node 24.19.0, Rspack 2.2.2, and memfs/fs-core 4.68.2, before the dependency upgrade to 4.79.0. These synthetic asset workloads measure output-heavy rebuilds, not application HMR.
Related: web-infra-dev/rsbuild#8595