[perf-improver] perf: fast-path IndexItems when no validator configured#479
Merged
Shazwazza merged 1 commit intoJun 17, 2026
Conversation
When ValueSetValidator is null (the common case - validator is an optional opt-in), the current code runs every ValueSet through a 3-stage LINQ chain: Select(ValidateItem) + Where(status != Failed) + Select(ValueSet). For each item, ValidateItem short-circuits to new ValueSetValidationResult(ValueSetValidationStatus.Valid, item) because the null-conditional evaluates to null. The Where clause then always passes (status == Valid), and Select unwraps the struct. With no validator, this is 100% wasteful overhead: - 3 iterator state-machine objects allocated per IndexItems call - 1 ValueSetValidationResult struct created per item (stack, but still traverses null-conditional path) This change adds an early-return when ValueSetValidator == null, passing the IEnumerable<ValueSet> straight through to PerformIndexItems. At indexing time — the primary hot path — this saves the LINQ wrapping overhead for every batch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3 tasks
Contributor
This was referenced Jun 24, 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 is an automated PR from Perf Improver, an AI assistant focused on performance.
Goal
Eliminate unnecessary LINQ overhead on the indexing hot path — every bulk
IndexItemscall currently wraps items in a 3-stage LINQ pipeline even when no validator is configured.Change
File:
src/Examine.Core/BaseIndexProvider.csWhen
ValueSetValidator == null(the common, default case — validators are an opt-in feature), the existing code runs everyValueSetthrough:ValidateItemshort-circuits viaValueSetValidator?.Validate(item) ?? new ValueSetValidationResult(Valid, item)— when the validator is null, it always returnsValid, so theWherealways passes andSelectalways unwraps.After: when no validator is set,
IndexItemspasses theIEnumerable<ValueSet>straight through toPerformIndexItemswith no wrapping:Performance Evidence
Methodology: Static code-path analysis + allocation counting.
IndexItemscallValidateItem→ null-conditional → struct ctorFor a batch of N documents:
ValueSetValidationResultstruct constructions + 2N lambda invocationsThis matters most in bulk indexing scenarios (e.g. rebuilding an index), where
IndexItemsis called with large sequences ofValueSetobjects.Trade-offs
nullcheck perIndexItemscall (negligible)Reproducibility
Test Status
✅ Build clean (0 errors, 0 new warnings). All 147 tests passed (2 skipped as expected).
Add this agentic workflows to your repo
To install this agentic workflow, run