Listing and seeding repeat per-file work (binary sniff, YAML parse, stat)

未关闭
#201 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
go, yaml
领域
cli, performance

调研方向

Read internal/walk/walk.go around ListWith and looksBinary, internal/seed/k8s.go around k8sLeads, and internal/seed/external.go around ignoreFiles. Start by running the existing walk and seed tests, then address one checklist item at a time; done means all three acceptance criteria hold and those tests pass unchanged.

由索引模型根据 Issue 内容生成。

描述

good first issue performance severity: low

Summary

Three small, independent costs in the deterministic scan path that grow with the number of files and are cheap to remove.

Where

  • internal/walk/walk.go:308, :391 (looksBinary inside the single-threaded walk)
  • internal/seed/k8s.go:66, :154, internal/seed/infra.go:59 (k8sLeads parses every YAML file in full)
  • internal/seed/external.go:400-435 (ignoreFiles stats once per listed file)

Details

  • Binary sniff is serial. ListWith opens, reads up to 8000 bytes and closes every regular file inside the WalkDir callback, on one goroutine, also when the map comes from the cache. Every listed file is opened again by the stage that reads it. Fix: collect candidates in the callback and sniff on a bounded worker pool (results stored by index so order is kept), as eachFile does for the seeders.
  • Kubernetes check parses first, filters second. k8sLeads builds a full YAML node tree for every non-workflow YAML file up to 1 MiB, and only then drops documents with no apiVersion or a non-workload kind. Fix: return early when the text contains neither apiVersion nor kind (accept the substring test only when the text holds no backslash, if escaped keys matter).
  • Ignore-file lookup stats per file. After semgrep or gitleaks returns, ignoreFiles calls os.Stat(<dir>/<ignore name>) for every listed file; the seen map only removes duplicates from the output. Fix: remember directories already checked.

Impact

Estimates from the code, not measured. At 100,000 listed files the serial sniff is about a second on Linux and an estimated 5 to 60 seconds on Windows under real-time antivirus; a repository with about 60 MB of non-Kubernetes YAML spends several CPU seconds per scan in the parser; with both scanners installed the ignore lookup makes 200,000 stats where a tenth would do.

Suggested fix

See the checklist above. Each item is independent and can land on its own.

Acceptance criteria

  • Binary sniffing runs on a worker pool and listing order is unchanged
  • k8sLeads skips files that cannot hold a workload without parsing them
  • ignoreFiles stats each directory once
  • Existing walk and seed tests pass unchanged

Related: #18, #90

Getting started

  • Relevant files: internal/seed/external.go, internal/seed/k8s.go, internal/walk/walk.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: low. Effort: S. audit-key: performance|internal/walk/walk.go|looksBinary

主要语言
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 摘要。