Repository navigation
Speed up pattern scanning and keep all batch hits
Rework the scan paths in PatternSearcher. Match results are unchanged,
except for the batch bug fix below. On a 34.6 MB .text section with
419 patterns, .NET 10, warm searcher:
Search(string[]) 36.8 ms -> 2.8 ms
419 x Search(string) 158 ms -> 37 ms
full-scan miss 3.77 ms -> 0.27 ms
first search, new searcher 30 ms -> 3 ms
- Build the frequency histogram in parallel chunks and derive the
single-byte counts from the pair counts (same values as before). - Choose anchors by how rarely the byte pair occurs, not by first-byte
rarity first. - Batch scans: replace IndexOfAny + Dictionary with one pass that tests
each byte pair against an 8 KB bitmap, with rank-indexed buckets.
Single-byte-anchored patterns share the same pass. Use 1 MB chunks
so all cores take part. - Single-pattern scans: an inline SIMD filter checks three rare bytes
at once. Ranges over 1 MB are scanned in parallel 256 KB blocks;
the first block runs on the calling thread. - All-hit results: one flat hit buffer per chunk instead of a List
per pattern.
Fix: SearchMany(string[]) on buffers of 256 KB or more dropped hits
that resolved to zero, and consecutive hits with equal resolved
values, because the parallel merge deduplicated values. Chunks never
report the same match twice, so every hit is now kept, as ISearcher
documents.
ISearcher: large scans may use thread-pool workers while the caller
waits; the remark no longer says they run only on the calling thread.