GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf: dir かもしれない event の L2 / L3 evict を batch あたり 1 走査にまとめる by ymnao · Pull Request #623 · ymnao/scripta

Conversation

@ymnao

@ymnao ymnao commented Oct 10, 2026

Copy link
Copy Markdown
Owner

概要

applyFsBatch は、dir かもしれない event(.md 以外の path か、isDir が付いたもの)が来るたびに、L2 ContentCache の entries と L3 InvertedIndex の pathToId を全件走査していました。そのため、cache の件数と batch 中の event 数を掛けた分だけ時間がかかり、git checkout / pull や zip の展開で画像が大量に入ってくると main process が 1 秒以上止まっていました。そうした path を batch ごとに Set に集め、L2・L3 をそれぞれ 1 回だけ走査する形に変えました。

vitest で 1 回計測(cache 10k 件) 変更前 変更後
非 .md の create 1000 件 1418ms 5.3ms
非 .md の delete 1000 件 1125ms 3.0ms
prefix の長さが約 60 種類ある create 1000 件 未計測 9.9ms
非 .md の create 1 件 2.3ms 2.8ms

最後の行は、どちらも 1 回だけ測った値です。差が誤差の範囲かどうかは確かめていません。

HANDOFF の「その他」にあった 177 の Tier3 第 1 項(非 .md の create でも prefix scan に入る)を実測したところ、次の 2 点で記述と違っていました。

  • create だけでなく delete も同じくらいかかる。
  • L3 は remove した後も pathToId に path を残すので、「新規 path は必ず 0 件ヒット」とは言えない。

そこで、create を対象から外すのではなく、走査そのものを 1 回にまとめる形で直しました。

関連 Issue

なし(HANDOFF.md の「177 で Tier3 と判定して三択に載せなかった 3 件」の第 1 項)

移行 Stage

  • Stage 0: 雛形 + フロント表示確認
  • Stage 1: ファイル I/O
  • Stage 2: ワークスペース・ファイルツリー・ファイル監視
  • Stage 3: 全文検索(ripgrep sidecar)
  • Stage 4: Git Sync
  • Stage 5: OGP / PDF / アップデート
  • Stage 6: 仕上げ・配布・切り替え

(該当なし。Stage 完了後の性能改善)

変更内容

  • root-relative-path.ts に atOrUnderMatcher(prefixes) を足した。判定範囲は旧述語 key === p || key.startsWith(p.endsWith(sep) ? p : p + sep) と同じ。
    • path の先頭を prefix の長さごとに切り出し、Set で引く。切り出し位置の前後どちらかが sep のときだけ引くので、/foo が /foobar に誤一致しない。
    • path の sep を indexOf で辿る形は採らなかった。event 1 件、cache 10k 件のとき 16ms かかり、旧実装の 2.3ms より遅かったため。
  • L2 の deletePrefix(prefix, prefixWithSep) を deletePrefixes(Set) に、L3 の invalidatePrefix(prefix) を invalidatePrefixes(Set) に置き換えた。
  • applyFsBatch は dir かもしれない path を集め、file event を処理した後でまとめて evict / invalidate する。
    • 順序を変えても次の 2 つは event 順に処理した場合と変わらない。変わるのは fileEpoch の採番値だけ。
      • L2 の entries、l2Generation、L3 の valid 集合
      • tombstone clear が起きるかどうか
    • 根拠は、batch の中では indexFile も getOrCreateId も走らないこと。この前提をコードのコメントに書いた。

動作確認

  • vitest run(全体): 142 files / 3321 tests pass(1 file / 18 tests skip)
  • tsc --noEmit(node / web / e2e): pass
  • biome format / biome check: 変更なし、エラーなし(info 1 件は既存の biome.json の schema 由来)
  • electron-vite build: pass
  • mutation 検証
    • matcher と applyFsBatch に当てた 8 mutant はすべて kill された。
    • 加えて、invalidatePrefixes 末尾の tombstone clear 判定を外す mutant を当てた。これは新しい閾値跨ぎの test だけが kill した(既存の test ではどれも落ちない)。
  • renderer-only / 実 Electron の e2e: ローカルでは未実施(sandbox 内では listen が EPERM になる)。CI で確認する。
  • 実機での体感確認: 未実施
検証エビデンス

リスク分類

tier: medium — reasons なし(classify-risk.sh の出力が "reasons": [])

実行した検証

種別 コマンド 結果
テスト ./node_modules/.bin/vitest run PASS 3321 passed / 18 skipped(143 files 中 142 passed / 1 skipped)
型 tsc --noEmit -p tsconfig.node.json / tsconfig.web.json / tsconfig.e2e.json PASS
Lint biome format --write . / biome check . No fixes applied、エラーなし
Build electron-vite build PASS
e2e pnpm test:e2e / pnpm test:e2e:electron 未実施(sandbox で EPERM になる。CI で確認する)
Mutation scratchpad の python スクリプトで 9 mutant 9 / 9 KILLED
レビュー /simplify(reuse / simplification / efficiency / altitude) 1 件 fix
レビュー code-reviewer(fable)1 周目 Critical 0 / Warning 0 / Suggestion 2(2 件 fix)
レビュー code-reviewer(fable)2 周目 Critical 0 / Warning 0 / Suggestion 3(3 件 fix)
レビュー codex-review security PASS(exit 0、findings 0)

レビュー指摘と対応

# 出所 指摘 対応
1 /simplify prefix 長の集合を二重に包んで組み立てている 修正済み(d4e7d0e)
2 code-reviewer 1 周目 順序非依存のコメントが、何を観測して同じなのかと、成り立つ前提を書いていない 修正済み(6db789e)
3 code-reviewer 1 周目 file event と dir event が合わせて tombstone 閾値を跨ぐ test が無い 修正済み(6db789e)
4 code-reviewer 2 周目 getOrCreateId は clear 側ではなく等値比較側の前提。「非減少」に「clear まで」の限定が無い 修正済み(d96b7bb)
5 code-reviewer 2 周目 isSaturated の assertion が何も判別していない 修正済み(d96b7bb)
6 code-reviewer 2 周目 閾値の算術コメントの形が前半と揃っていない 修正済み(d96b7bb)

code-reviewer は 1 周目で次を独立に確かめました。

  • matcher の範囲が旧述語と一致すること(解析と、乱数 200,014 件の突き合わせで不一致 0)
  • 処理順を変えても状態が変わらないこと(inverted-index.ts を読んだうえでの論証)

追跡先

backlog delta: 起票 0 件 / 本 PR で close 0 件 / 現在 open 2 件

なし

Draft 判定

  • 判定: normal
  • 根拠: step 4 — 確認された finding はすべて本 PR で fix 済み。(b) / (c) は無い

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ymnao and others added 4 commits October 10, 2026 13:42
@ymnao @claude
perf: dir かもしれない event の L2 / L3 evict を batch あたり 1 走査にまとめる
cf19691
- applyFsBatch は非 `.md` (または isDir) の event ごとに L2 entries と L3 pathToId を全走査していた。cache 1 万件に非 `.md` の create を 1000 件流すと 1418ms、delete で 1125ms main を塞いでいた (vitest で 1 回計測)
- batch 内の dir かもしれない path を Set に集め、L2 deletePrefixes / L3 invalidatePrefixes で 1 走査にした。同じ条件で create 5.3ms / delete 3.0ms
- 範囲判定は atOrUnderMatcher (root-relative-path.ts) に置いた。旧 `exact || startsWith(prefix + sep)` と同じ範囲になる。prefix の長さごとに先頭を切り出して Set で引く形にしたのは、path の sep を indexOf で辿る形だと event 1 件のとき 10k 件で 16ms になり、旧実装 (2.3ms) より遅かったため
- evict と bump はどれも可換で、tombstone clear も batch 内では tombstone 数が単調増加なので発火の有無が変わらない。file event の後にまとめても結果は event 順と同じ

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymnao @claude
refactor: atOrUnderMatcher の prefix 長集合の組み立てを素直なループにする
d4e7d0e
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymnao @claude
test: file event と dir event が合わせて tombstone 閾値を跨ぐ batch の L3 clear を…
6db789e
… pin する

- 一括化で prefix invalidate を file event の後ろに回したので、既存 test が避けていた「batch 内で閾値を跨ぐ」経路を 1 件踏む。invalidatePrefixes 末尾の clear 判定を外す mutant はこの test だけが kill する
- applyFsBatch のコメントで、順序を変えても同じになるものを観測対象ごとに書き、成り立つ前提 (batch 内で indexFile / getOrCreateId が走らない) を明示した

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymnao @claude
docs: applyFsBatch の順序非依存コメントで前提を主張ごとに付け直す
d96b7bb
- getOrCreateId は clear ではなく等値比較側の前提なので分けて書いた
- 判別していない isSaturated の assertion を外し、閾値の算術コメントの形を揃えた

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymnao
ymnao merged commit 3c50e21 into main Oct 10, 2026
10 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ymnao
ymnao deleted the refactor/batch-prefix-evict branch October 10, 2026 06:24
@ymnao ymnao mentioned this pull request Oct 12, 2026
chore: v0.8.0 リリース準備 #632
Merged
4 of 11 tasks
ymnao added a commit that referenced this pull request Oct 12, 2026
@ymnao @claude
chore: v0.8.0 リリース準備 (#632)
9d003d3
* chore: v0.8.0 リリース準備

- package.json の version を 0.7.0 → 0.8.0 に上げる
- CHANGELOG.md に v0.8.0 のエントリを追加する (#283 〜 #631、170 commit)
  - Electron 44 で macOS の最小要件が 13 (Ventura) に上がることを冒頭に明記する
    (同梱 Electron 44.5.1 の LSMinimumSystemVersion が 13.0)
  - リリース後、tap 側で Cask の depends_on macos を :ventura に上げてから
    autobump を手動実行する (docs/parity-checklist.md §11)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: v0.8.0 の CHANGELOG をコミットの実態に合わせて直す

- hard link (#601) は検索結果の stale 対策で、ワークスペース外アクセスの封鎖では
  ないので Security から Fixed へ移す
- 漏れていた #414 / #443 / #623 と CI actions の更新を足す
- #461 の 3 経路 (別タブのファイルへの書き込み・rename 前パスの復活・
  ウィンドウを閉じたときの保存漏れ) を分けて書く
- #444 を wikilink がすべて未解決になる症状として、#622 を Fixed として書き直す
- electron-builder の完全一致固定に出所 (#283) と理由を添える
- [0.8.0] / [0.7.0] の参照リンク定義を足し、README の Electron 版を v44 に直す

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: v0.8.0 の CHANGELOG の #623 / #443 の記述を実測条件と実際の UI に合わせる

- #623 の「1 秒以上」に実測条件 (キャッシュ 1 万件・イベント 1000 件) を添え、
  コミットに無い git checkout の例を外す
- #443 の「すべて表示した」は実在しない UI 文言なので、打ち切りの通知が
  出ないという実挙動で書く

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@ymnao
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.