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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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.

Copy link
Contributor

Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo!

@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.

@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.

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
3 participants