[性能分析器] 在共享目录热路径中懒加载文件流扫描错误映射
作者: github-actions[bot]创建于 2026年9月28日更新于 2026年9月28日
标签needs_team
Hot Path
filebeat/input/filestream/fscanner.go:318-380 in scan-state construction and result assembly (newScanState, recordUnobservable, recordVanished, results).
The current path eagerly allocates and sorts error-tracking collections on every scan, even when there are no path errors:
- eager map init in
newScanState(unobservable,vanished) - unconditional sorted key extraction in
results()
Profiling Data
Before:
go test -run '^$' -bench '^BenchmarkGetFilesSharedDir/inputs400$' -benchmem -count=5 ./filebeat/input/filestream
BenchmarkGetFilesSharedDir/inputs400-4 56 20648141 ns/op 1028769 B/op 9618 allocs/op
BenchmarkGetFilesSharedDir/inputs400-4 56 20498608 ns/op 1028624 B/op 9618 allocs/op
BenchmarkGetFilesSharedDir/inputs400-4 56 20509263 ns/op 1028620 B/op 9618 allocs/op
BenchmarkGetFilesSharedDir/inputs400-4 50 20637638 ns/op 1028961 B/op 9620 allocs/op
BenchmarkGetFilesSharedDir/inputs400-4 58 20820442 ns/op 1028573 B/op 9617 allocs/opProposed Change
Use lazy allocation/materialization in the no-error fast path:
- remove eager
unobservable/vanishedmap allocation innewScanState - allocate these maps only on first insert in
recordUnobservableandrecordVanished - in
results(), only callslices.Sorted(maps.Keys(...))when map length is non-zero
内容来源: elastic/beats