perf(server): dev 起動・初回アクセスを計測・改善 - #601
Conversation
Consolidate route generation, defer dev RPC initialization, and add isolated cold-start measurements.
|
Warning Review limit reached
Next review available in: 38 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough開発サーバーの起動計測機能を追加し、隔離ランタイム、ブラウザ計測、RPC遅延ロード、ワーカー起動制御、route tree生成設定、計測ドキュメントを更新しました。 Changes開発サーバー起動計測
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Runner as measure-dev-startup.ts
participant Server as bun run dev
participant Browser as measure-dev-startup-browser.ts
participant RPC as devOrpcNodeMiddlewarePlugin
Runner->>Server: 隔離環境と環境変数で起動
Runner->>Browser: base URL と開始時刻を渡す
Browser->>Server: 静的アセットと /config を取得
Browser->>RPC: config.get RPC を実行
RPC-->>Browser: RPC応答
Browser-->>Runner: BrowserMeasurement JSON
Server-->>Runner: ログマイルストーン
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/server/vite.config.ts (1)
113-141: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
getDevRpcHandlerが失敗したPromiseを永続キャッシュしリトライ不能になる
devRpcHandlerPromise ??= loadDevRpcHandler();は、初回の動的import/初期化が一時的な理由(HMR中の一時的なモジュール解決失敗など)で失敗した場合でも、reject済みのPromiseをそのままキャッシュし続けます。??=はundefinedの場合のみ再代入するため、以降のすべてのRPCリクエストが同じ失敗を再現し、開発サーバーを再起動するまで復旧できません。🛠️ 提案: 失敗時にキャッシュをリセットする
function getDevRpcHandler(): ReturnType<typeof loadDevRpcHandler> { - devRpcHandlerPromise ??= loadDevRpcHandler(); + devRpcHandlerPromise ??= loadDevRpcHandler().catch((error) => { + devRpcHandlerPromise = undefined; + throw error; + }); return devRpcHandlerPromise; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/server/vite.config.ts` around lines 113 - 141, Update getDevRpcHandler so a rejected loadDevRpcHandler promise clears devRpcHandlerPromise before propagating the error, allowing subsequent requests to retry initialization; preserve caching for successful resolutions.
🧹 Nitpick comments (2)
apps/server/scripts/measure-dev-startup-browser.ts (1)
112-116: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSSR成功判定を文言依存から独立させる余地
ssrHtml.includes('Save Changes')はUI文言に依存しています。文言変更時にすぐ気づける設計(明確なエラーを投げる)にはなっていますが、data-testid等の安定したマーカーに置き換えるとUI copy変更の影響を受けにくくなります。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/server/scripts/measure-dev-startup-browser.ts` around lines 112 - 116, Replace the UI-text check in the SSR response validation near ssrHtml and firstSsrHtmlAtMs with a stable selector or data-testid marker for the settings form. Keep throwing a clear error when that marker is absent, without relying on the “Save Changes” copy.apps/server/scripts/isolated-runtime.ts (1)
147-181: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
prepareIsolatedRuntimeに安全性チェックを内蔵すべき
prepareIsolatedRuntimeは呼び出し側が事前にassertSafeRuntimeDirを呼ぶことを前提に、無条件でrm(runtimeDir, { recursive: true, force: true })を実行します。現在の呼び出し元(e2e-server.ts、measure-dev-startup.ts)はいずれも正しく事前チェックしていますが、この関数自体は破壊的操作を伴う共有APIであるため、将来の呼び出し元がチェックを忘れた場合に意図しないディレクトリを再帰削除するリスクがあります。♻️ 提案: 内部でも検証する
export async function prepareIsolatedRuntime( runtimeDir: string, + allowedRuntimeRoot: string, ): Promise<IsolatedRuntime> { + assertSafeRuntimeDir(runtimeDir, allowedRuntimeRoot); await rm(runtimeDir, { recursive: true, force: true }); await mkdir(runtimeDir, { recursive: true });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/server/scripts/isolated-runtime.ts` around lines 147 - 181, prepareIsolatedRuntime の冒頭で、再帰削除を実行する前に assertSafeRuntimeDir(runtimeDir) を呼び出して内部検証を行ってください。既存の呼び出し側による事前チェックには依存せず、検証後にのみ rm、mkdir、設定書き込み、seedMediaFixtures を続行させます。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/server/scripts/measure-dev-startup.ts`:
- Around line 241-249: runMeasurement の runtimeDir 生成を更新し、Vite transform cache
の影響を比較できるよう、毎回一意な runtimeDir を作るモードに加えて同一 runtimeDir を再利用するフラグ、または cacheDir
のみを固定する切り替えを追加してください。既存の安全性検証と通常のコールドスタート計測は維持し、キャッシュ比較時は実行間で対象キャッシュが保持されるようにします。
In `@docs/design/web-rendering-strategy.md`:
- Around line 146-147: Update the worker/maintenance startup condition in the
TanStack Start development flow to explicitly state that it begins exactly once
after completion of the first RPC response with a 2xx status. Replace the
ambiguous “successful RPC response” wording while preserving the existing
lazy-import and single-start behavior.
---
Outside diff comments:
In `@apps/server/vite.config.ts`:
- Around line 113-141: Update getDevRpcHandler so a rejected loadDevRpcHandler
promise clears devRpcHandlerPromise before propagating the error, allowing
subsequent requests to retry initialization; preserve caching for successful
resolutions.
---
Nitpick comments:
In `@apps/server/scripts/isolated-runtime.ts`:
- Around line 147-181: prepareIsolatedRuntime の冒頭で、再帰削除を実行する前に
assertSafeRuntimeDir(runtimeDir)
を呼び出して内部検証を行ってください。既存の呼び出し側による事前チェックには依存せず、検証後にのみ
rm、mkdir、設定書き込み、seedMediaFixtures を続行させます。
In `@apps/server/scripts/measure-dev-startup-browser.ts`:
- Around line 112-116: Replace the UI-text check in the SSR response validation
near ssrHtml and firstSsrHtmlAtMs with a stable selector or data-testid marker
for the settings form. Keep throwing a clear error when that marker is absent,
without relying on the “Save Changes” copy.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 6d75ccc1-a111-4287-a11c-47614bec4b8c
📒 Files selected for processing (12)
apps/server/package.jsonapps/server/scripts/e2e-server.tsapps/server/scripts/isolated-runtime.tsapps/server/scripts/measure-dev-startup-browser.tsapps/server/scripts/measure-dev-startup-schema.tsapps/server/scripts/measure-dev-startup.tsapps/server/src/infrastructure/server-route-bootstrap.tsapps/server/src/routes/api/rpc.$.tsapps/server/src/routes/api/sources.$mediaSourceId.$mediaId.tsapps/server/src/routes/api/sources.$mediaSourceId.thumbnail.$mediaId.tsapps/server/vite.config.tsdocs/design/web-rendering-strategy.md
概要
Issue #600 の dev server 起動・初回アクセスを隔離環境で計測し、初期化と worker 起動経路を整理します。
Closes #600
変更内容
検証
Summary by CodeRabbit
新機能
改善
ドキュメント