fix(indexer): bound zoekt code search #82
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!82
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/bound-zoekt-code-search"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The code indexer passes zoekt a bare
SearchOptions, so every limit is zero:zoekt does ship caps for exactly this, in
SearchOptions.SetDefaults:but
SetDefaultsis only ever called from zoekt's owncmd/binaries and from the index builder, never on the search path. A caller that buildsSearchOptionsby hand opts out of the protection without meaning to.Combined with
Whole: true, which attaches the full body of every matching file, one query materialises the whole corpus into memory beforepaginateResultscuts it down to a single page.Measured
Against a live instance with 2726 shards, using zoekt directly against the same index directory so the numbers isolate the search itself:
importerrorpackage mainEvery one of those renders 20 results.
With the caps in this PR, same corpus, same queries:
importerrorpackage mainValues
ShardMaxMatchCountandTotalMaxMatchCountare zoekt's own defaults. They do not bind at this corpus size and are there as insurance for a larger one.MaxWallTimeis 2s. zoekt's own web server uses 10s; a page render wants to be well inside that. It did not trigger in any measurement above, so it is a ceiling for pathological queries rather than a limit on normal ones.MaxDocDisplayCountis 1000, matching the result cap GitHub applies to its code search. This is the one doing the work: it truncates after collating, so the file bodies beyond the first thousand are never materialised.Tradeoff
The result total and the page count become capped rather than exact: a query matching 178k files now reports 1000. Deep pagination past the cap is no longer possible. That is the same behaviour GitHub has, and the alternative is a request that can occupy a core for 23 seconds.