BattleSearch: Fix pathological regex #10679
Open
+4
−2
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.
PCRE lookahead was causing the regex to be pathologically slow.
The lookahead was introduced by #7801 , the purpose of which I (eventually) inferred to be to handle out-of-order player IDs.
I.e., you do
/battlesearch alice, bob
and also want to match battles where p1 was bob and p2 was alice.Cases I've tested:
files with no matches
, andsearch 1 ID w/ matches in either slot
, andsearch 2 ID w/ matches in either order
.Measured perf on directory with 500K files, 8GB, all non-matches.
Low-end cacheless NVMe SSD.
File cache was cleared each run with
echo 3 | sudo tee /proc/sys/vm/drop_caches
.Before: 100% CPU usage, 1MB/s disk read.
After: 20% CPU usage, 500MB/s disk read.
When testing, I had to disable a couple permission checks, disable ripgrep's gitignore behavior and import
Monitor
to actually be able to run this. Those changes are visible at larry-the-table-guy@b519ef6 . That is the code I tested and measured with, and then I copied the relevant changes to this PR branch.Chatlog
was also touched by #7801, but it seems that feature has since been moved to a DB, so IDK if it's worth changing that one as well.