[efficiency-improver] perf: eliminate LINQ Select+Where+ToList+ToArray allocation in TaxonomySearchContext.SearchableFields - #590
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…archContext.SearchableFields Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🤖 This PR was created by Efficiency Improver, an automated AI assistant.
Focus Area
Code-Level Efficiency
Goal
TaxonomySearchContext.SearchableFieldsbuilt its result withMultiFields.GetMergedFieldInfos(reader).Select(x => x.Name).ToList()followed by a second.Where(...).ToArray()chain. This allocates two LINQ iterator/state-machine objects (Select + Where) plus an intermediateList<string>buffer, on every rebuild of the searchable-fields cache. The sibling classSearchContext.SearchableFieldsalready had this exact pattern eliminated in PR #545, butTaxonomySearchContext(used for the facets/taxonomy search path) was missed.Approach
Replaced the two-stage LINQ chain with a single pre-sized
List<string>(capacity =FieldInfos.Count) populated via oneforeachloop that inlines the filter condition, then materialized once with.ToArray(). Removed the now-unusedusing System.Linq;and addedusing System.Collections.Generic;. Behavior is unchanged — same field names, same order, same filtering of special/facet fields, same caching semantics (only non-empty results are cached).Energy Efficiency Evidence
Proxy metric: memory allocation (reduced iterator/state-machine + intermediate list allocations), which maps to energy via reduced GC/DRAM churn — the same methodology used in the previously-merged PR #545 for the equivalent
SearchContext.SearchableFieldsfix.This method rebuilds at most once per
TaxonomySearchContextlifetime (or once per empty-index probe), so per-call savings are small, but the pattern eliminates 2 iterator allocations + 1 intermediateList<string>per rebuild with zero behavioral change.Green Software Foundation Context
Trade-offs
None identified — public API/behavior unchanged. The explicit loop is marginally more verbose than the LINQ chain but stays simple and matches the already-established pattern in
SearchContext.SearchableFields.Test Status
dotnet build src/Examine.sln --configuration Release— succeeded, 0 errors, 0 warnings.dotnet test src/Examine.Test/Examine.Test.csproj -f net8.0 --configuration Release— 316 passed, 0 failed, 2 skipped.Reproducibility
dotnet build src/Examine.sln --configuration Release dotnet test src/Examine.Test/Examine.Test.csproj -f net8.0 --configuration ReleaseAdd this agentic workflow to your repo
To install this agentic workflow, run