scan --staged exports and re-maps the whole index on every commit

未關閉
#183 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
58/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
git, go

研究方向

Start with internal/engine/diffscan.go and internal/engine/run.go to trace the staged scan, then inspect ExportIndex and mkdirAllReadable in internal/gitx/gitx.go and cache behavior in internal/mapper/mapper.go. Run the staged scan tests and add coverage for a clean work tree and an unstaged edit on top of a staged one. Done means the clean case skips export, the staged scan reuses HEAD's cached map, and each export directory is created once.

由索引模型根據 Issue 內容生成。

描述

help wanted performance severity: medium

Summary

The pre-commit path (scan --staged) writes every tracked file to an export directory, maps all of it from scratch and deletes it, so the hook's time grows with the size of the repository, not with the size of the commit.

Where

  • internal/gitx/gitx.go:906-924, :976-1006 (ExportIndex, writeBlobs)
  • internal/gitx/gitx.go:848-861 (mkdirAllReadable: one Mkdir per path segment per file)
  • internal/engine/diffscan.go:248 (exportStaged)
  • internal/engine/run.go:186-208, :468 (mapOpts.Changed set only for --changed; RememberSecrets over the whole export)
  • internal/mapper/mapper.go:115-141 (no HEAD in the export, so no cache applies)
  • .pre-commit-hooks.yaml:7 (hooks run scan --staged --offline with always_run: true)

Details

ExportIndex keeps every stage-0 regular entry of git ls-files --stage and writes each blob. The changed set is never passed in. The export is a fresh git init with no HEAD, so gitx.HeadSHA fails in mapper.Build and neither the commit cache nor the HEAD-plus-changed cache applies: the whole export is listed, binary-sniffed and mapped, then RememberSecrets parses every Dockerfile, Terraform and YAML file in it. Only the seeders are limited to the staged files.

Impact

Derived from the code, not measured. For a repository of 20,000 tracked files and 300 MB, each commit costs 20,000 file creates, about 100,000 extra Mkdir calls, 300 MB written and read back, and 20,000 deletes, for a one-line change. On Windows, where small-file creation under real-time antivirus is in the millisecond range per file, the hook goes from sub-second to tens of seconds. A --changed scan of the same tree reuses the cached map of HEAD and reads only the changed files.

Suggested fix

Make the work proportional to the commit, while keeping "what was scanned is what the commit will contain". (1) Fast path: when no tracked file differs between the work tree and the index (the usual case), skip the export and scan the work tree with the changed set, as --changed does. (2) Otherwise pass the real repository's HEAD and the changed set to the mapper so it can load the cached map of HEAD and read only the staged files, and export only what differs. Independently, have mkdirAllReadable remember directories it already created during one export.

Acceptance criteria

  • A staged scan with a clean work tree does not write an export
  • A staged scan reuses the cached map of HEAD
  • mkdirAllReadable creates each directory once per export
  • The staged-content guarantee of #149 still holds (test with an unstaged edit on top of a staged one)

Related: #149, #121

Getting started

  • Relevant files: .pre-commit-hooks.yaml, internal/engine/diffscan.go, internal/engine/run.go, internal/gitx/gitx.go, internal/mapper/mapper.go
  • How to run tests: make test-short (Unix) or .\make.ps1 test-short (Windows PowerShell); make lint before you call it done
  • Related docs: CONTRIBUTING.md, docs/ARCHITECTURE.md

Filed by repo-audit/full-audit at 50e92ec. Severity: medium. Effort: M. audit-key: performance|internal/gitx/gitx.go|ExportIndex

主要語言
Go
星號
0
分支
1
平均合併
8 小時 14 分鐘
30 天內合併 PR
3

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TMHSDigital/Spackle 的其他 Issue

查看 TMHSDigital/Spackle 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。