Repository navigation
Reduce abstract schema validation overhead and allocations - #10158
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes HotChocolate schema validation by reducing per-event rule scanning and eliminating validation-event allocations, aiming to lower both runtime and GC pressure during schema builds.
Changes:
- Cache the handler set per validation event type per
SchemaValidatorinstance to avoid repeatedis/OfTypescanning for every published event. - Convert validation events from
sealed recordtoreadonly record structand adjustIValidationEventHandler<TEvent>to remove contravariance to support struct events. - Micro-optimizations in validation rules (ordinal
__prefix check; reduce allocations in interface implementation validation).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Core/src/Types.Validation/SchemaValidator.cs | Caches per-event handler arrays to avoid re-scanning all rules for each published validation event. |
| src/HotChocolate/Core/src/Types.Validation/Rules/ValidNameRule.cs | Uses ordinal comparison for reserved-name detection to avoid culture-sensitive overhead. |
| src/HotChocolate/Core/src/Types.Validation/Rules/ValidImplementationsRule.cs | Avoids allocating error lists and argument dictionaries unless needed during interface-implementation checks. |
| src/HotChocolate/Core/src/Types.Validation/Events/ValidationEvents.cs | Converts validation events to readonly record struct to eliminate per-event allocations. |
| src/HotChocolate/Core/src/Types.Validation/Events/Contracts/IValidationEventHandler.cs | Removes in variance to align with struct-based events and updated dispatch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Patch coverage95.1% of changed lines covered (58/61)
Uncovered changed lines (JSON){
"sha": "0685ce1ab4dc473d4c3ec6d63ea26f4642734b0e",
"files": [
{ "path": "src/HotChocolate/Core/src/Types.Validation/Events/ValidationEvents.cs", "ranges": [[60, 60], [105, 105], [110, 110]] }
]
}Project coverage: 53.9% (232774/431566 lines) |
This was referenced Aug 6, 2026
Merged
This was referenced Aug 13, 2026
Closed
Closed
This was referenced Aug 25, 2026
Closed
Closed
This was referenced Sep 7, 2026
Closed
This was referenced Sep 15, 2026
Closed
[nuget][SUI_Matcher]- Bump the sui-package-updates group with 20 updates
DFE-Digital/SUI_Matcher#405
Closed
This was referenced Sep 22, 2026
Closed
Closed
[nuget][SUI_Matcher]- Bump the sui-package-updates group with 20 updates
DFE-Digital/SUI_Matcher#410
Merged
This was referenced Oct 5, 2026
This was referenced Oct 19, 2026
This was referenced Oct 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.
Summary
SchemaValidatorresolves the handler set for each event type once per validator, instead of type-testing every rule against every published event. Validating the GitHub public schema publishes 49,899 events, so the old linear scan performed roughly 898,000 interface type tests per validation.readonly record struct, so publishing an event no longer allocates. This requiresIValidationEventHandler<TEvent>to drop itsinvariance, which value types cannot satisfy. Both changes are breaking for anyone implementing custom rules outside this repository.ValidNameRulecompares the__prefix ordinally rather than culture-sensitively, andValidImplementationsRulebuilds its log-entry lists only when it has something to report and resolves implemented arguments by name instead of building a dictionary per field.Test plan
dotnet test src/HotChocolate/Core/test/Types.Validation.Tests— 129 passingdotnet test src/HotChocolate/Fusion/test/Fusion.Composition.Tests— 712 passing, exercising the mutable-schema consumer