Skip to content

Small improvements to reduce allocations in validation filter logic #62056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 28, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 22, 2025

I'm implementing improvements to reduce allocations in the validation filter logic. Here's my progress so far:

  • Avoid allocating arrays in ValidationEndpointFilterFactory.Create for parameters that don't require validation
    • Replaced fixed-size arrays with a List of structs containing only the validatable parameters
    • Only parameters that need validation are stored, improving memory usage when most parameters don't need validation
  • Optimize ValidationContext reuse throughout the pipeline to avoid creating new ones per handler argument
  • Reduce closure allocations in EndpointFilterDelegate returned from the filter factory
  • Cache reflection calls for implemented subtypes in ValidatableTypeInfo

These changes will make the validation filter logic more efficient and pay-to-play, reducing allocations when users are not leveraging the feature.

Fixes #61222.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Copilot finished work on behalf of captainsafia May 22, 2025 01:18
@captainsafia
Copy link
Member

@gfoidl Thanks for posting these comments! I've been trying out the new Copilot feature to see how helpful it can be. One of its limitations is that it only responds to feedback from the person who initiated it. I'll go through your comments and add them under my own review so the agent can be triggered.

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start! More feedback to address here.

…ve code style

Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Copilot finished work on behalf of captainsafia May 22, 2025 16:21
@captainsafia captainsafia marked this pull request as ready for review May 22, 2025 16:39
@captainsafia captainsafia requested a review from halter73 as a code owner May 22, 2025 16:39
@captainsafia captainsafia changed the title [WIP] Consider improvements to reduce allocations in validation filter logic Small improvements to reduce allocations in validation filter logic May 22, 2025
@captainsafia
Copy link
Member

@BrennanConroy Thoughts on this change? It didn't execute on all the items in the original list but I think this change is good as is.

One thing to note is that we have no benchmarks for the validation filter specifically (that's my bad) so we don't have a good way of getting numbers here but assuming the change doesn't break any tests the delta here feels straightforward to review.

…datable parameters

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Copilot finished work on behalf of BrennanConroy May 22, 2025 18:57
Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use collection expressions here.

Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented May 23, 2025

Let's use collection expressions here.

I've updated the code to use collection expressions in commit a600bcd.

@captainsafia captainsafia enabled auto-merge (squash) May 28, 2025 17:49
@captainsafia captainsafia merged commit 83c7bf0 into main May 28, 2025
25 of 27 checks passed
@captainsafia captainsafia deleted the copilot/fix-61222 branch May 28, 2025 18:46
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview6 milestone May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider improvements to reduce allocations in validation filter logic
4 participants