rspack-perf

Optimizes CPU and memory hot paths in the Rspack Rust bundler codebase.

12.9k|843|Updated Apr 1, 2022
One-click install
npx skills add https://github.com/web-infra-dev/rspack --skill rspack-perf
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rspack-perf
Source: https://github.com/web-infra-dev/rspack/tree/main/.agents/skills/rspack-perf
Command: npx skills add https://github.com/web-infra-dev/rspack --skill rspack-perf

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rspack contributors working on performance issues often lack a systematic method for identifying which internal data structures dominate a hot path, leading to optimizations that target low-cardinality structures while ignoring dependencies and export infos that are orders of magnitude more numerous.

Core Features & Use Cases

  • Cardinality-driven analysis: Ranks internal structures (dependency/export_info > module > chunk > chunk_group > entry/runtime) to focus optimization effort where full scans and repeated traversals are most dangerous.
  • CPU optimization techniques: Covers caching stable results, avoiding repeated traversal, fast paths for common cases, deferred work, batched state updates, algorithmic complexity reduction, and dispatch overhead reduction.
  • Memory optimization techniques: Covers string churn reduction, cloning avoidance, temporary container reduction, key-shape-appropriate data structures, and keeping hot structs small.
  • Validation and PR workflow: Enforces running unit tests, formatters, and clippy, then guides creating a perf/ branch, conventional perf commit, PR, and triggering the Ecosystem Benchmark workflow with regression analysis.
  • Use Case: A contributor notices slow incremental rebuilds on a large project; the skill guides them to profile the dependency graph traversal, add a reverse index, batch graph updates, validate with pnpm run test:unit, and open a benchmarked perf PR.

Quick Start

Use $rspack-perf to analyze and optimize the slow compilation stage I describe, following its cardinality model and validation steps.

Frequently Asked Questions about rspack-perf

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize Rspack build performance in the codebase?

Start by identifying the target feature or compilation stage and the dominant data structures it touches, then estimate whether the hot path scales with dependencies, exports, modules, or chunks. Apply targeted CPU techniques like caching stable results, avoiding repeated traversal, and batching state updates before considering parallelism.

How to reduce memory usage in Rspack compilation?

Reduce string churn by preferring &str, Atom, or Arc<str> over repeated format! and to_string calls, and avoid cloning whole module or chunk structures when only a small field is needed. Also avoid creating temporary Vec or HashMap containers inside high-cardinality loops and keep cold metadata out of hot structs.

When should I use rayon versus rspack_parallel in Rspack?

Use rayon for CPU-bound synchronous work and rspack_parallel abstractions for async orchestration. Avoid mixing rayon and tokio pools inside one workflow without a clear boundary, and only add parallelism after removing repeated serial work.

What validation is required before submitting a Rspack performance PR?

Run pnpm run build:cli:dev followed by pnpm run test:unit, then pnpm run format:rs, pnpm run format:js, and cargo clippy --workspace --all-targets --all-features. The PR must use a perf/ branch, a conventional perf commit message, and trigger the Ecosystem Benchmark workflow.

Why do Rspack optimizations sometimes cause benchmark regressions?

Regressions often come from optimizing around chunks or runtimes while ignoring that dependencies and export infos are far more numerous, adding caches without clear invalidation boundaries, or trading CPU bottlenecks for large temporary allocations. Analyze the changed hot path's cardinality and allocation behavior, then iterate once more if a plausible fix exists.