Skip to content

perf: 検索・ツリー・ライブリロード・静的配信を高速化 - #34

Merged
simota merged 1 commit into
mainfrom
perf/server-and-tree-optimizations
Nov 9, 2026
Merged

simota merged 1 commit into
mainfrom
perf/server-and-tree-optimizations

Conversation

@simota

@simota simota commented Nov 9, 2026

Copy link
Copy Markdown
Owner

概要

既存の機能・API 出力を変えずに、実測で確認したボトルネックを解消します。

# 変更 同一性の根拠
1 純 ASCII (ESC/SO/SI なし) のファイルは文字コード判定 (jschardet) を省略 対応する全エンコーディングで、これらのバイト列は同じ文字にデコードされる (ISO-2022-JP のみ ESC/SO/SI が例外のため除外)。lib/text-decode.mjs に切り出し
2 通常検索: ファイル全体を小文字化して含有を事前判定し、含まないファイルは行単位の走査を省略 各行の小文字化結果がファイル全体の小文字化結果の部分文字列になることを、ギリシャ語の語末シグマ・İ・結合文字を含む約 41.5 万行のファジングで確認
3 /api/tree: ディレクトリ内エントリの stat を最大 8 並列 (lib/concurrency.mjs) サブディレクトリは従来どおり逐次処理し、readdir 順を保持。1 リクエストあたりの同時処理数とメモリは有界
4 ファイルツリー: SSE の add/unlink 連続イベントを、実行中の取得 + 追従 1 回に集約 単発イベントは即時に処理 (遅延の追加なし)。最後の取得は最後のイベントより後に始まる
5 /assets/* (Vite のハッシュ付きファイル) に Cache-Control: public, max-age=31536000, immutable を付与 index.html・SPA フォールバック応答・ハッシュなしファイルは対象外

測定結果 (7,020 ファイルのフィクスチャ、各 2〜3 回測定)

指標 変更前 変更後
検索 (ヒットなし) p50 / CPU 4,835ms / 5,575ms 1,397ms / 1,322ms
検索 (「line 79」) p50 250ms 67ms
バックリンク p50 281ms 109ms
/api/tree p50 357ms 212ms
/api/tree (59,100 ファイル) p50 3,040ms 1,790ms
/api/tree 4 並列実行時の p50 800ms 778ms (同等)
200 ファイル一括追加: ツリーへの反映時間 / /api/tree 回数 / サーバー CPU 51.6s / 200 回 / 57.3s 0.8s / 2 回 / 0.68s
リロード時の転送量 7,857kB 48kB
起動時間 p50 約 130ms 約 130ms (同等)
ピーク RSS 中規模では低下、大規模ではノイズ範囲 —

採用しなかった案

  • 共有リミッターでツリー全体を並列化する設計: 並行負荷時にレイテンシ +14%、ピーク RSS が 224MB → 330MB に悪化したため、ディレクトリ単位の設計に変更
  • 検索・バックリンク・リンクチェックの先読み並列化: 結果上限で早期終了する場合に余分なファイルを読み、ディスク I/O が増えるため見送り

テスト

  • 追加: tests/text-decode.test.mjs (常に検出器を使う旧実装との一致: エッジケース・ファジング・リポジトリ内全ファイル)、tests/concurrency.test.mjs、tests/server-audit.test.mjs に検索とツリーの出力を固定するテスト 2 件。追加したサーバーテストは変更前のコードでも成功することを確認済み
  • npm run test:unit: 53 件成功 / 1 件スキップ (既存のもの)
  • npx playwright test: 418 件成功 / 3 件スキップ (ローカル実行時はプリインストールの Chromium を使用)
  • tsc / vite build / npm run check:contrast: 成功
  • エッジケース (シンボリックリンク・Office パッケージ・隠しフォルダ・.docviewignore・Shift_JIS・meta charset) を含む 3 種類のフィクスチャで、主要 API のレスポンスが変更前とバイト単位で一致

未検証

  • ネットワークファイルシステム、Windows、macOS 上での性能

Generated by Claude Code

- テキストデコード: 純 ASCII (ESC/SO/SI なし) のファイルは jschardet を省略。
  対応する全エンコーディングでデコード結果が同一になるため出力は不変
  (lib/text-decode.mjs に切り出し)
- 通常検索: ファイル全体の小文字化で含有を事前判定し、該当しないファイルの
  行分割・走査を省略
- /api/tree: ディレクトリ内エントリの stat を最大 8 並列で実行
  (サブディレクトリは従来どおり逐次、readdir 順を保持)
- ファイルツリー: SSE の add/unlink 連続イベントを、実行中の再取得 + 追従 1 回に集約
- /assets/* (ハッシュ付き) に Cache-Control: immutable を付与

ベースラインとの API 出力のバイト一致、ユニットテスト 53 件、E2E 418 件の成功を確認。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4uUUeXGVEGsFu5bRYbQAU
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T01:22:15.376894Z 62e8d91 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@simota
simota merged commit 0c1c6c1 into main Nov 9, 2026
3 checks passed
@simota
simota deleted the perf/server-and-tree-optimizations branch November 9, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants