Add API to release compilation memory after close without unloading native binding
Summary
Long-running Node embedders that call rspack() repeatedly in the same process often see RSS stay elevated after compiler.close(). Heap usage may look stable, but resident memory remains high for the lifetime of the process.
Compiler::close() runs plugin close hooks and cache shutdown; it does not replace or drop Compiler.compilation. The module graph, code generation results, and emitted assets therefore stay in Rust until the JS Compiler / native JsCompiler wrapper is garbage-collected (and the Rust Compiler is dropped on finalize when unsafeFastDrop is false).
That makes close() alone insufficient for embedders that want to keep the process and the warm @rspack/binding native module loaded between builds.
Request
An explicit, opt-in API (e.g. compiler.releaseCompilation() after close()) that:
- Replaces the last
Compilationwith a fresh empty one (same idea as thefast_setpath used at the start ofbuild()). - Cleans N-API wrapper registries for the previous
CompilationId. - Keeps the
JsCompilershell, the mapped.nodeaddon, and the process runtime (Tokio, etc.) alive for the next build.
Callers would invoke it after reading Stats. Accessing Stats or native chunk/module handles for the old compilation after release should fail clearly.
Related context
- #8702 — Stats usable after close; release must remain opt-in so default close semantics stay unchanged.
- #11920 —
unsafeFastDrop; not a substitute for releasing compilation data. - #14734 — RSS retention after close in repeated in-process builds (closed; reopen not available from our account).
- #14736 — JS wrapper cleanup on GC; does not drop the Rust module graph.
Environment
Generic Node embedder; native @rspack/core / @rspack/binding, non-watch one-shot or repeated builds in one process.
Source: web-infra-dev/rspack