Optimize fileset matching with hash-based indexing for performance improvement at high file counts #45203
+570
−43
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Linear scanning to match files by fingerprint became a bottleneck at high file counts. The reason is each poll iterated through all readers for every match operation.
I implemented some changes that saw could help to reduce the CPU usage like:
reflect.ValueOf()comparison dispatch (allocating ~48 bytes per call) with simpleCompareModeenum.unsafe.Stringwithout copying. Results cached per fingerprint.Maybe there are more improvements we can do. Or maybe this PR brings some ideas about some other enhancements.
Link to tracking issue
Fixes #27404
Testing
go test ./pkg/stanza/fileconsumer-bench BenchmarkPollManyFiles -benchmem