perf(hooks): skip unused JS hook register calls with a shared hook usage buffer#13612
perf(hooks): skip unused JS hook register calls with a shared hook usage buffer#13612
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8354e20148
ℹ️ 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".
Rsdoctor Bundle Diff AnalysisFound 6 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
There was a problem hiding this comment.
Pull request overview
This PR introduces a cross-language “hook usage” tracking mechanism so the Rust hook adapter can skip calling into JS to register taps for hooks that were never used (tapped/intercepted), reducing overhead in common builds.
Changes:
- Add a
JsHookUsageTrackerthat records hook usage into a small shared buffer and wires tracking into core/builtin hook surfaces. - Pass the shared usage buffer into the N-API
JsCompilerand use it in Rust (HookUsageChecker) to skip unused JS register calls. - Mark internal interceptors (e.g. tracing) so they don’t accidentally count as “hook usage” and defeat the optimization.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/rspack/src/trace/traceHookPlugin.ts | Marks tracing interceptors as internal so they don’t trigger usage bits. |
| packages/rspack/src/NormalModuleFactory.ts | Adds optional usage tracker wiring for factory hooks. |
| packages/rspack/src/HookUsageTracker.ts | New shared-buffer tracker + helpers to mark/track hook usage. |
| packages/rspack/src/ContextModuleFactory.ts | Adds optional usage tracker wiring for factory hooks. |
| packages/rspack/src/Compiler.ts | Instantiates tracker, resets bits per compilation, passes buffer to binding, marks internal interceptor. |
| packages/rspack/src/Compilation.ts | Wires usage tracking for compilation hooks + HookMap hook usage. |
| packages/rspack/src/builtin-plugin/RuntimePlugin.ts | Tracks usage for RuntimePlugin compilation hooks. |
| packages/rspack/src/builtin-plugin/RsdoctorPlugin.ts | Tracks usage for Rsdoctor compilation hooks. |
| packages/rspack/src/builtin-plugin/JavascriptModulesPlugin.ts | Tracks usage for JS modules chunkHash hook. |
| packages/rspack/src/builtin-plugin/html-plugin/hooks.ts | Tracks usage for Html plugin hooks. |
| crates/rspack_binding_api/src/plugins/js_hooks_plugin.rs | Threads the hook usage buffer into the adapter and into each register wrapper. |
| crates/rspack_binding_api/src/plugins/interceptor.rs | Adds HookUsageChecker and uses it to skip register calls; includes unit tests. |
| crates/rspack_binding_api/src/lib.rs | Extends JsCompiler constructor to accept the hook usage buffer; removes old non-skippable API. |
| crates/node_binding/napi-binding.d.ts | Updates TypeScript declarations for the new JsCompiler constructor signature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📦 Binary Size-limit
🎉 Size decreased by 3.84KB from 49.38MB to 49.37MB (⬇️0.01%) |
8554929 to
cb2b369
Compare
|
📝 Benchmark detail: Open
|
12d8180 to
f24cc38
Compare
Deploying rspack with
|
| Latest commit: |
3851781
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ab78405b.rspack-v2.pages.dev |
| Branch Preview URL: | https://perf-hooks-register-schedule.rspack-v2.pages.dev |
|
📝 Benchmark detail: Open
|
|
📝 Benchmark detail: Open
|
Summary
This PR optimizes JS hook dispatch by introducing a shared hook usage buffer between JS and Rust.
hookUsageBuffertobinding.JsCompilerso Rust can check whether a JS hook has any taps before callingregisterXXXTapsJsHookUsageTrackeron the JS side and track hook usage by patching lite-tapable_tap,intercept(), andHookMapfactory hooksWeakMapinstead of exposing internal getter APIsnon_skippable_registersflow entirelyhook_usage_buffera required binding parameterRelated links
Checklist