uid index rebuilt per check and scripts re-read outside the per-run cache

オープン
#126 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
godot, typescript

調査の方向性

Start with src/project/files.ts:14-59 to understand the per-run read cache, then trace the listed call sites in src/scenes/validate.ts, uids.ts and scene-graph.ts. Add a projectReport test that counts fs.readFileSync calls, as suggested, and use it to check the acceptance criteria: each file is read at most once per report run and no module-global file cache remains.

索引モデルが issue の本文から書いたものです。

説明

performance severity: medium

Summary

The per-run "one walk, one read" index (#87) is bypassed in three places:

  • The uid index is rebuilt by each check.
  • Scripts are re-read in connection and registry checks.
  • scene-graph.ts keeps its own process-global script cache, which is never evicted.

On a modern Godot 4.4+ project, report performs about 17.9k file reads for 6.5k files.

Where

  • src/scenes/validate.ts:73-76, :184, :238, :315 (lazyUidIndex(root) is created separately in validateScenes, validateProjectConfig and validateRegistries)
  • src/scenes/uids.ts:16-31 (buildUidIndex walks the whole tree and reads every .tscn/.tres in full, only to use the first 512 characters)
  • src/scenes/scene-graph.ts:148-163 (scriptInfo: module-global scriptCache keyed by absolute path, validated by mtime and size, never evicted; one statSync per [connection])
  • src/scenes/validate.ts:233, :290-297, :333, :361 (project.godot, readClassName and registry .tres files are read with readFileSync instead of readSource)
  • Compare src/project/files.ts:14-59

Details

Measured on a synthetic project with 3000 .gd (each with a .uid sidecar), 300 .tscn and 200 registry .tres files, with run/main_scene="uid://...":

Read count Files Reads
.uid 3000 9000
.tscn 300 1200
.tres 200 800
.gd (validate-scenes) 3000 5700, plus 2701 statSync calls

readClassName reads the same script once per registry entry. Building the uid index alone costs about 1.4 s. Rebuilding it pushes report from about 22 s to about 25 s (roughly 12%).

The global scriptCache behaves differently from everything else in a long-lived MCP server. It holds entries for every project seen, and it misses edits that keep the same mtime and size.

Impact

report and project_report time grows with asset and connection counts, and is worst on Windows and network filesystems. New checks have to choose between three caching models.

Suggested fix

  1. Add a test that counts reads per projectReport (spy on fs.readFileSync) and records today's number.
  2. Memoise the uid index in the per-run index (keyed by cfg and root, like readSource), and read only the head of .tscn/.tres files, or reuse readSource content.
  3. Route scriptInfo, readClassName, project.godot and the registry .tres reads through readSource. Delete the module-global scriptCache, or move it into the per-run index.
  4. Lower the read count asserted in the step-1 test.

Acceptance criteria

  • Each file is read at most once per report run.
  • No module-global file cache remains.

Filed by repo-audit/full-audit at e836036. Severity: medium. Effort: M. audit-key: performance|src/scenes/validate.ts|lazyUidIndex

主要言語
TypeScript
スター
0
フォーク
6
平均マージ
1日 21時間
マージ済み PR(30日)
8

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TMHSDigital/godot-correctness-mcp のほかの issue

TMHSDigital/godot-correctness-mcp の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。