perf: don't drop rust compiler instance in non-watch mode#11920
perf: don't drop rust compiler instance in non-watch mode#11920
Conversation
✅ Deploy Preview for rspack canceled.
|
|
📝 Benchmark detail: Open
|
📦 Binary Size-limit
❌ Size increased by 640bytes from 47.67MB to 47.67MB (⬆️0.00%) |
CodSpeed Performance ReportMerging #11920 will not alter performanceComparing Summary
Footnotes |
|
📝 Benchmark detail: Open
|
7df0084 to
efa8399
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes non-watch builds by avoiding costly Rust compiler teardown. It introduces an internal unsafeFastDrop flag that propagates from the CLI to the Rust binding, conditionally skipping drop in finalize to improve performance.
- Add internal unsafeFastDrop flag to Compiler and a setter on MultiCompiler; CLI sets it when not in watch mode
- Update Rust binding to wrap Compiler in ManuallyDrop and conditionally drop in finalize based on the flag
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/rspack/src/MultiCompiler.ts | Adds a setter to propagate unsafeFastDrop to child compilers |
| packages/rspack/src/Compiler.ts | Adds unsafeFastDrop property and forwards it into the native binding constructor |
| packages/rspack/etc/core.api.md | Updates API report for new internal field/setter |
| packages/rspack-cli/src/cli.ts | Sets unsafeFastDrop in non-watch mode to skip drop overhead |
| crates/rspack_binding_api/src/lib.rs | Wraps Compiler in ManuallyDrop and conditionally drops in finalize |
Comments suppressed due to low confidence (1)
crates/rspack_binding_api/src/lib.rs:1
- self.compiler is ManuallyDrop; calling methods directly on it will not compile. Obtain a reference to the inner Compiler (e.g., via as_ptr) before calling id(). For example: let compiler_ref: &Compiler = unsafe { &*self.compiler.as_ptr() }; let compiler_id = compiler_ref.id();
#![recursion_limit = "256"]
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
should we need move the option into experiments? |
Summary
It's slow and unnecessary to drop the Compiler & Compilation in non-watch mode, so support to ignore drop of Compiler & Compilation instance in non-watch mode
Related links
Checklist