The mapper reads and regex-scans every file on one goroutine, mostly for nothing

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

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
1-2 天
新手友好度
55/100
Issue 類型
重構
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
go
領域
performance

研究方向

Start in internal/mapper/mapper.go at Build (around lines 126-147), where files are read before walk.IsTestPath is checked, and at scanFile (around lines 339-343), which runs all importFrameworks patterns on every line. Compare how entryPatterns is indexed by language, and look at MaxHeldText in internal/walk/texts.go. Run go test ./internal/mapper before and after; done means test files and unsupported languages are not read, the golden maps are unchanged, and result order is stable.

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

描述

performance severity: medium

Summary

mapper.Build reads each source file and runs every import-framework regex on every line, on one goroutine, before the parallel seeders run. It reads test files before a path-only test check, and scans Java, Ruby, PHP and C# files although no pattern exists for them.

Where

  • internal/mapper/mapper.go:126-147 (read before walk.IsTestPath)
  • internal/mapper/mapper.go:339-343 (scanFile runs all 13 importFrameworks patterns on every line)
  • internal/walk/texts.go:6 (MaxHeldText = 64 << 20)

Details

Past 64 MiB of source, text read by the mapper is not held for the seeders, so most of a large repository is read twice, which #18 set out to stop.

Impact

Estimated (not measured): on a 100k-file repository, several minutes of single-core work on every scan of a new commit, which in CI is every scan.

Suggested fix

  1. Check walk.IsTestPath before reading; skip languages with no patterns.
  2. Index importFrameworks by language, as entryPatterns already is.
  3. Run the per-file part through a worker pool (or inside the seeders' shared pass), collecting results by file index so order stays stable.

Acceptance criteria

  • Mapper tests and golden maps are unchanged.
  • Test files and unsupported languages are not read by the mapper.

Related: #18

Getting started

  • Relevant files: internal/mapper/mapper.go, internal/walk/texts.go
  • How to run tests: make test (Unix) or .\make.ps1 test (Windows PowerShell); one package: go test ./internal/<pkg>

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

主要語言
Go
星號
0
分支
1
PR 合併指標
30 天內沒有已合併 PR

環境準備

在 Codespaces 中開啟

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

從這裡開始

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

TMHSDigital/Spackle 的其他 Issue

查看 TMHSDigital/Spackle 的全部 Issue

相似的 Issue

更多 Go Issue

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

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