Skip to content
cccskills
FreePublished on GitHub

perf-loop

Rust の性能改善を「計測 → 仮説 → 変更 → 再計測」のループで地道に回すためのスキル。プロファイラの選び方、Cargo の最適化設定、データ構造・アロケーション・ハッシュ・分岐などの定石をフェーズ順に適用する。1 回 1 変更 1 計測の規律を厳守する。

rsvelte 固有の既知ボトルネック(`serde_json::Value` 駆逐、`bumpalo` 導入、`Atom<'a>`、codegen 直書き)と OXC 対応表、NAPI 検証手順も §7 に収録。「Rust の性能改善」「ボトルネック調査」「プロファイル取って最適化」などの依頼で使用。

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md9.2 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Rust Performance Loop

0. 規律

  1. 計測なき最適化は禁止。着手前にベースラインを取る。
  2. 1 変更 = 1 計測。同時に複数を混ぜない。
  3. 効かなければ revert。±5% はノイズ。
  4. プロファイル上位 5 関数に入らないコードは触らない。
  5. 毎周 cargo test --release。正しさ > 速さ。
  6. 最適化後に読みにくくなったらアプローチを疑う。

1. ループ

baseline → profile → 仮説(N% 効くはず、を明文化)→ 1 変更 → test → 同条件で再計測
  → 改善: commit / 改善なし: revert + perf log に 1 行

止めどき: 上位 5 関数を触り目標の 80% 達成 / 残るホット関数が <5% / 次案が可読性を壊して期待 <5% / 3 周で 1% も動かない。

2. 計測ツール

目的ツール
E2E 実時間hyperfine --warmup 3(10 回以上)
関数単位criterion(crates/rsvelte_bench/benches/ci.rs、CodSpeed)
CPU サンプリングsamply(第一選択)/ Instruments / /usr/bin/sample
アロケーションdhat / crates/rsvelte_devtools/src/bin/alloc_sites.rs
キャッシュ・分岐perf stat / cachegrind
生成コードcargo asm / --emit=llvm-ir(最後の手段)

3. ビルド設定(Cargo.toml に定義済み)

profile用途
releaselto="fat", codegen-units=1, panic="abort", strip=false, debug=false — 計測の基準
profilingrelease 継承、lto="thin", codegen-units=16, debug="line-tables-only" — samply 用
benchcriterion 用(常に unwind)
dist配布用(strip="symbols")
RUSTFLAGS="-C force-frame-pointers=yes" cargo build --profile profiling -p rsvelte_devtools --bin profiler

PGO: scripts/perf/pgo.sh が pgo/rsvelte.profdata を再生成、scripts/perf/assert-pgo-profile.sh が magic を検査(壊れた profile は warning のみでビルドが通る)。scripts/bench/pgo-env.mjs が cargo spawn に適用。

4. プレイブック(効く順)

段手典型
A 構造ビッグオー / 中間表現削除 / 計算そのものの削除 / fast path桁
B allocarena, &str/Cow, SmallVec, compact_str, Box<[T]>, .clone() 駆除, with_capacity, format!→write!2〜10x
C レイアウトenum サイズを size_of assert で固定・大バリアント Box、u32 位置、フィールド順、SoA1.1〜1.5x
D ハッシュFxHashMap/ahash、小さければ線形探索、phf1.2〜2x
E ミクロ#[inline]/#[cold]、branchless、memchr/SIMD、from_utf8_unchecked(要根拠)1.05〜1.3x
F 並列単スレッドを絞ってから rayon。グローバル Mutex 禁止—

アンチパターン: LLVM 既済みの手最適化 / マイクロ勝ちマクロ負け / コールド最適化 / 数値なしコミット。

5. 計測ハザード(この箱・このリポ固有)

  • 静かな箱: ps -Ao %cpu=,comm= | sort -rn | head の先頭を読む。cargo==0 でも mds_stores/mediaanalysisd がビルド直後に 90% 超。陽性対照 yes > /dev/null が最上位に出ること。
  • 比は時間で対にする: official/rsvelte を同一ラウンド内で back-to-back、ABBA で順序交互。別々に測った比は drift。
  • 壁時計でなく CPU 時間: perf_bench の CPU median を読む。壁時計は負荷で 2 倍動く。
  • アームの同一性: ファイル名・パス・ブランチは信用しない。Compiling <crate> (<path>) 行、2 成果物の sha256、出力での判別プローブ(含むべきもの/欠くべきもの両方)を読む。
  • worktree: 毎回 cd <worktree> && CARGO_TARGET_DIR=<worktree>/target cargo …。cwd は黙ってリセットされる。
  • ディスク: df -g /System/Volumes/Data が 20 GiB 未満なら cargo を起動しない。debug の target/debug/deps は 1 バイナリ ~140 MB × ls crates/rsvelte_core/tests/*.rs | wc -l 本(積を持ち歩かない — AGENTS.md 参照)。
  • 分母: 共有型(JsNode 等)を触ったら --workspace。| tail/2>/dev/null 越しに verdict を読まない。
  • call count を先に読む: 決定的。時間は 1 回ではノイズ。
  • 同居エージェント: 計測窓の開始/終了は宣言で伝える。他人の窓の中で cargo を叩かない。
  • 未測定は未測定と書く: 未確定のまま入れた変更は全て戻された。

6. $ARGUMENTS

  1. continue → 直近 perf log を読み次ループ。
  2. 関数名/モジュール名 → そこに絞る。
  3. 空 → samply で全体を測り上位 5 を提示(§7.1 の --profile 内訳は使わない)。
  4. 順序厳守: baseline → profile → 仮説(ユーザー確認)→ 変更 → test → 再計測 → keep/revert。
  5. 1 イテレーション 1 報告、3 周ごとに要約。

7. rsvelte 固有

7.1 計測コマンド

./scripts/bench/bench.sh --quick        # JS vs Rust 単線比較
./scripts/bench/bench.sh --criterion    # criterion
cargo build --release -p rsvelte_devtools --bin perf_bench
target/release/perf_bench --target client --runs 9 [--threads N] [--skip S --limit L]   # A/B の主計器
cargo build --profile profiling -p rsvelte_devtools --bin profiler
samply record target/profiling/profiler --file big.svelte --iterations 100
cargo build --profile profiling -p rsvelte_devtools --bin corpus_share_profile --features mimalloc-alloc
samply record --save-only -o prof.json.gz -r 1000 -- target/profiling/corpus_share_profile --iters 4
node scripts/bench/profile-shares.mjs prof.json.gz 30   # self/inclusive share 表
cargo run --release -p rsvelte_devtools --bin compile_profile -- --target server [--dev]  # フェーズ内訳
pnpm benchmark:reproduce                # サイト報告(scripts/reports/run-performance.mjs)

profiler / bench.sh --profile のフェーズ配分は本番経路と違う(retained script なし、TS 除去なし)。「parse:analyze:transform = X:Y:Z」の根拠に使わない。samply の相対ホットスポットには使える。

7.2 既知ボトルネック

項目現状手順grep
A serde_json::Value 駆逐62 ファイルが依存。JsNode/TypedExpr(crates/rsvelte_core/src/ast/typed_expr.rs)へ寄せるExpression::Value 生成箇所を JsNode に置換 → 不足バリアント追加 → ホットパスから外すrg 'serde_json::Value' crates/rsvelte_core/src -l
B arenabumpalo は依存に入り、ast/arena.rs は JsNodeId 索引アリーナ。lifetime 付き Box<'a,T>/Vec<'a,T> 化は未着手AST に 'a 導入 → Parser<'a>{alloc} 貫通 → パーサ層から段階的にrg bumpalo crates/rsvelte_core/src
C Atom<'a>CompactString。重複はコピーソース直結の識別子を &'a str に → 生成文字列は arena → 頻出はインターン—
D codegen 直書きJsNode → 文字列の 2 段String バッファに write! 直書き、with_capacity—
E .clone()transform に多い&/Rc/Cowrg '\.clone\(\)' crates/rsvelte_core/src/compiler/phases/3_transform -c
F パーサSvelte テンプレートのみ自前&[u8] 走査、正規表現禁止、借用徹底—

現状の数値と alloc 分析は docs/phase3-ast-refactor-plan.md を読む。

7.3 OXC 対応

OXC役割参照場面
oxc_allocatorarena7.2 B
oxc_asttyped AST7.2 A/B
oxc_parserJS/TS parser7.2 F
oxc_codegencodegen7.2 D
oxc_spanAtom<'a>/Span7.2 C
oxc_syntax演算子表キーワード判定

ソース: ls ~/.cargo/registry/src/*/oxc_<crate>-*/src/

7.4 NAPI 経由 E2E

cargo build --release -p rsvelte_napi --lib
node scripts/compat-corpus/binding.mjs --stage      # .corpus-cache/rsvelte.node
pnpm corpus:verify && pnpm corpus:matrix           # 出力バイト同一ゲート
cargo test --release                                # runtime/ssr/hydration

Vite 経路は apps/npm/vite-plugin-svelte。最終確認は必ず NAPI 経由。

8. References

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

PR の CI 失敗を修正し、全 CI がパスするまでプッシュ→待機→修正を繰り返す。「/ci-fix-and-verify [PR番号]」「CI直して」「CIが落ちてる」「CI修正」などの依頼時に使用。

The English summary is being prepared. Showing the original description.

baseballyama/rsvelte242Updated Oct 18, 2026

PR 提出前にコードオーナー視点でフルレビューする。WHY の理解 → 設計 → AST/基盤型 → 実装(複数 Agent の順次レビュー)の順に、各フェーズでユーザーと対話しながら指摘を修正し、品質に問題がなくなるまで繰り返す。「/full-code-review」「フルレビュー」「レビューして」などの依頼時に使用。rsvelte(公式 Svelte コンパイラの Rust ポート)専用。

The English summary is being prepared. Showing the original description.

baseballyama/rsvelte242Updated Oct 18, 2026

Audit and clean up the repository — remove dead files, fix naming inconsistencies, update .gitignore, and ensure the repo is well-organized for OSS contributors. Does NOT modify source code logic.

The English summary is being prepared. Showing the original description.

baseballyama/rsvelte242Updated Oct 18, 2026

GitHub PR のコードレビューコメントに対応する。未 resolve のみを抽出 → 対応方針をユーザー承認 → 1 件ずつ修正+返信 → AI レビュー由来の指摘はナレッジに反映するワークフロー。「/review-response [PR番号]」「レビュー対応」「レビューに返信」などの依頼時に使用。

The English summary is being prepared. Showing the original description.

baseballyama/rsvelte242Updated Oct 18, 2026

Upgrade the Svelte submodule to the latest (or specified) version, regenerate fixtures, identify test failures, and fix all regressions until tests pass 100%.

The English summary is being prepared. Showing the original description.

baseballyama/rsvelte242Updated Oct 18, 2026

Svelte を使う外部リポジトリ(ツール / ライブラリ / アプリ)を git submodule として取り込み、Svelte コンパイラを rsvelte に差し替えても完全に同等に動作するかを検証する。既存のサブモジュールが指定された場合は最新化したうえで再検証し、回帰があれば rsvelte 側を自動修正する。「/verify-svelte-compat <url-or-name>」で実行。

The English summary is being prepared. Showing the original description.

baseballyama/rsvelte242Updated Oct 18, 2026

See all skills by baseballyama

Report a problem with this skill