--changed scans never use the map cache, so each one remaps the whole tree

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
50/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
cli, performance

調査の方向性

Start in internal/mapper/mapper.go: the cache check around lines 103-120 and the full build at 127-153, which calls scanFile per file. Then look at internal/engine/run.go around lines 158-170, where the changed set is already known before mapper.Build runs. Done means a --changed scan with a cached HEAD map rescans only the changed files, its result equals a full build of the same dirty tree (added, modified and deleted cases), and no cache entry is written for a dirty tree. Verify with go test ./internal/mapper ./internal/engine.

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

説明

help wanted performance severity: medium

Summary

A --changed scan only has work to do when the working tree is dirty, and the map cache is only used when the tree is clean. So every --changed scan rebuilds the whole repository map, even when one file changed and HEAD's map is already cached.

Where

  • internal/mapper/mapper.go:103-120 (cache used only when IsCleanExcept is true)
  • internal/mapper/mapper.go:127-153 (full single-goroutine build)
  • internal/engine/run.go:158-170 (the changed set is known before mapper.Build)
  • internal/mcp/tools.go:373-380 (MCP scan with changed)

Details

if clean, cerr := gitx.IsCleanExcept(ctx, root, stateDirName); cerr == nil && clean {
    commit = sha
}
...
if commit != "" && opts.CacheDir != "" {
    if m, ok := loadCache(opts.CacheDir, commit); ok {

With a dirty tree, commit stays "", so loadCache is skipped and Build reads and regex-scans every supported file. run.go already has the changed-file list before it calls the mapper, but the mapper does not use it.

Impact

--changed is the mode meant to run repeatedly while editing, from the CLI, a pre-commit hook or an MCP client's edit loop. Each run pays the full mapper pass that #90 estimates at minutes on a 100k-file repository. If #88 (seed only the changed files) is fixed, this pass becomes the main fixed cost of a --changed scan. A --since scan on a dirty CI checkout has the same cost.

Steps to reproduce

  1. On a clean tree, run spackle scan . once (writes .spackle/cache/map-<sha>.json).
  2. Edit one file and run spackle scan --changed ..
  3. The cache is not read, the map step takes as long as a cold scan, and no cache file is written.

Suggested fix

In a diff scan (changed != nil), pass the changed set into mapper.Build. Load HEAD's cached map even though the tree is dirty, then rescan only the changed files with scanFile: drop their old Entry and Boundaries rows, add the new ones, and recount languages and infra files from the current listing. If HEAD has no cached map, fall back to the full build. Keep refusing to save a cache entry for a dirty tree.

Acceptance criteria

  • A --changed scan with a cached map for HEAD rescans only the changed files.
  • The resulting map equals a full build of the same dirty tree (test with an added, a modified and a deleted file).
  • No cache entry is written for a dirty tree.

Getting started

  • Relevant files: internal/mapper/mapper.go, internal/engine/run.go
  • How to run tests: go test ./internal/mapper ./internal/engine

Related: #88, #90


Filed by repo-audit/full-audit at fffef43. Severity: medium. Effort: M. audit-key: performance|internal/mapper/mapper.go|Build dirty-tree cache

主要言語
Go
スター
0
フォーク
1
PR マージ指標
30日以内にマージされた PR はありません

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

TMHSDigital/Spackle のほかの issue

TMHSDigital/Spackle の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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