Summary
DbSymbolReader.SearchSymbols() / CountSearchSymbols() (src/CodeIndex/Database/DbSymbolReader.cs:122-141, 378) normalize the queries input array by chaining .Select().Where().Distinct().ToList(). At lines 124 and 139 the .ToList() forces a materialization, but when validQueries.Count > 1 line 141 immediately recurses into SearchSymbols(validQueries, ...), which re-runs the same normalization on already-normalized input. Repeated normalization adds GC pressure for queries with many distinct terms.
Where
src/CodeIndex/Database/DbSymbolReader.cs:122-141 (AnySearchSymbols / CountSearchSymbols)
src/CodeIndex/Database/DbSymbolReader.cs:378 (ExcludeUsedSymbols — same pattern)
src/CodeIndex/Database/DbSymbolReader.cs:235, 330 (AnalyzeSymbol — .Where().Distinct().ToList())
Suggested approach
- Extract query normalization into one method returning
IReadOnlyList<string>; cache the result on first call per input.
- Change recursion call sites to pass the already-normalized list and have the callee detect it.
- Use
HashSet<string> where order is unimportant; reserve Distinct().ToList() for cases that need ordered output.
- Make the public method accept
IReadOnlyList<string> and document that callers should pre-normalize when possible.
- Add a unit test that asserts normalization runs once per distinct input set.
- Run a benchmark with a 50-term query and verify allocations drop materially.
Summary
DbSymbolReader.SearchSymbols()/CountSearchSymbols()(src/CodeIndex/Database/DbSymbolReader.cs:122-141, 378) normalize thequeriesinput array by chaining.Select().Where().Distinct().ToList(). At lines 124 and 139 the.ToList()forces a materialization, but whenvalidQueries.Count > 1line 141 immediately recurses intoSearchSymbols(validQueries, ...), which re-runs the same normalization on already-normalized input. Repeated normalization adds GC pressure for queries with many distinct terms.Where
src/CodeIndex/Database/DbSymbolReader.cs:122-141(AnySearchSymbols / CountSearchSymbols)src/CodeIndex/Database/DbSymbolReader.cs:378(ExcludeUsedSymbols — same pattern)src/CodeIndex/Database/DbSymbolReader.cs:235, 330(AnalyzeSymbol —.Where().Distinct().ToList())Suggested approach
IReadOnlyList<string>; cache the result on first call per input.HashSet<string>where order is unimportant; reserveDistinct().ToList()for cases that need ordered output.IReadOnlyList<string>and document that callers should pre-normalize when possible.