$npx -y skills add rstackjs/agent-skills --skill rspack-tracingComprehensive guide and toolkit for diagnosing Rspack build issues. Quickly identify where crashes/errors occur, or perform detailed performance profiling to resolve bottlenecks. Use when the user encounters build failures, slow builds, or wants to optimize Rspack performance.
| 1 | # Rspack Tracing & Performance Profiling |
| 2 | |
| 3 | ## When to Use This Skill |
| 4 | |
| 5 | Use this skill when you need to: |
| 6 | |
| 7 | 1. Diagnose why an Rspack build is slow. |
| 8 | 2. Understand which plugins or loaders are taking the most time. |
| 9 | 3. Analyze a user-provided Rspack trace file. |
| 10 | 4. Guide a user to capture a performance profile. |
| 11 | |
| 12 | ## Workflow |
| 13 | |
| 14 | ### 1. Capture a Trace |
| 15 | |
| 16 | First, ask the user to run their build with tracing enabled. |
| 17 | |
| 18 | ```bash |
| 19 | # Set environment variables for logging to a file |
| 20 | RSPACK_PROFILE=TRACE RSPACK_TRACE_LAYER=logger RSPACK_TRACE_OUTPUT=./trace.json pnpm build |
| 21 | ``` |
| 22 | |
| 23 | This will generate a trace file in a timestamped directory like `.rspack-profile-{timestamp}-{pid}/trace.json`. |
| 24 | |
| 25 | See [references/tracing-guide.md](references/tracing-guide.md) for more details on configuration. |
| 26 | |
| 27 | ### 2. Quick Diagnosis for Crashes/Errors |
| 28 | |
| 29 | If the user wants to identify **which stage a crash or error occurred in**, use `tail` to quickly view the last events without running the full analysis: |
| 30 | |
| 31 | ```bash |
| 32 | # Navigate to the generated profile directory |
| 33 | cd .rspack-profile-*/ |
| 34 | |
| 35 | # View the last 20 events to see where the build failed |
| 36 | tail -n 20 trace.json |
| 37 | ``` |
| 38 | |
| 39 | The last events will show the span names and targets where the build stopped, helping to quickly pinpoint the problematic stage, plugin, or loader. |
| 40 | |
| 41 | ### 3. Full Performance Analysis |
| 42 | |
| 43 | For detailed performance profiling (not just crash diagnosis), ask the user to run the bundled analysis script on the generated trace file. |
| 44 | |
| 45 | ```bash |
| 46 | # Navigate to the generated profile directory |
| 47 | cd .rspack-profile-*/ |
| 48 | |
| 49 | # Run the analysis script |
| 50 | node ${CLAUDE_PLUGIN_ROOT}/skills/tracing/scripts/analyze_trace.js trace.json |
| 51 | ``` |
| 52 | |
| 53 | ### 4. Interpret Results |
| 54 | |
| 55 | Use the output from the script to identify bottlenecks. |
| 56 | Consult [references/bottlenecks.md](references/bottlenecks.md) to map span names to actionable fixes. |
| 57 | |
| 58 | ### 5. Locate Slow Plugins |
| 59 | |
| 60 | Based on the "Top Slowest Hooks" from the analysis script: |
| 61 | |
| 62 | 1. **Identify the Hook**: Note the hook name (e.g., `hook:CompilationOptimizeChunks`). |
| 63 | 2. **Inspect Configuration**: Read `rspack.config.js` or `rsbuild.config.ts`. |
| 64 | 3. **Map Hook to Plugin**: Look for plugins and their sources that tap into that specific hook. |
| 65 | 4. **Output**: Output the paths, lines and columns of the suspected plugin source code. |
| 66 | |
| 67 | ## Common Scenarios & Quick Fixes |
| 68 | |
| 69 | - [Bottleneck Reference](references/bottlenecks.md): Mapping spans to concepts. |
| 70 | - [Tracing Guide](references/tracing-guide.md): Detailed usage of `RSPACK_PROFILE`. |