perf(hopper): resolve string search records once per query (#1229)
* perf(hopper): resolve string search records once per query search_strings called _string_inventory(document) once per match, and each call sorts every string address and rebuilds the record dict, so a query cost O(matches x strings log strings). Resolve the inventory once per search. Warm search, 50% matches, fake document, best of 7: 1000 strings 186 -> 0.5 ms, 4000 strings 3161 -> 2.1 ms, 8000 strings 13121 -> 4.9 ms; output byte-identical. * perf(hopper): skip record resolution for empty string searches Resolving the full string inventory for a query with no matches added a sort of every string address that the previous code never performed. Return early when nothing matches. Zero-match search on a warm document, best of 7: 64000 strings 35.9 ms before this change, 4.0 ms after (main: 3.9 ms).
This commit is contained in:
@@ -553,7 +553,12 @@ def _search_results(document, kind, params):
|
||||
if not matches(item[1]):
|
||||
continue
|
||||
selected.append(item)
|
||||
return [{"address": address, **_string_inventory(document)[address]} for address, _ in selected] if kind == "string" else [
|
||||
if not selected:
|
||||
return []
|
||||
if kind == "string":
|
||||
records = _string_inventory(document)
|
||||
return [{"address": address, **records[address]} for address, _ in selected]
|
||||
return [
|
||||
{
|
||||
"address": address,
|
||||
"value": value,
|
||||
|
||||
Reference in New Issue
Block a user