-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Avoid allocations in more cases #9788
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
Conversation
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
rynowak
commented
Apr 26, 2019
rynowak
commented
Apr 26, 2019
rynowak
commented
Apr 26, 2019
rynowak
commented
Apr 26, 2019
rynowak
commented
Apr 26, 2019
rynowak
commented
Apr 26, 2019
Eilon
reviewed
Apr 26, 2019
davidfowl
approved these changes
Apr 26, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve this message
What allocations are left? Just the selector context? |
JamesNK
approved these changes
Apr 26, 2019
Selector context - AND the |
Updates to DFA Matcher to avoid allocations in more cases. This makes the matcher more pay-for-play. - Avoid allocating an RVD while matching if possible - Avoid allocating the candidate set unless necessary First, avoid creating the RVD unless there are parameters or constraints. This means that the candidate set can contain null route value dictionaries. This seems fine because selectors are already low-level. The route values feature will allocate an RVD when accessed, so code in MVC or middleware won't even see a null RVD. Secondly, avoid creating the candidate set unless there are selectors. This will save an allocation most of the time since we won't need to run selectors is really common cases. The candidate set is needed because selectors mix mutability and async, so it needs to be a reference type. However the default case is that we *don't* need to run selectors. The impact of this is that we make a bunch of methods have an instance variant and a static variant that operates on the array.
8f21d41
to
510fa81
Compare
This was referenced Oct 23, 2020
This was referenced Apr 15, 2021
This was referenced Apr 26, 2021
This was referenced Sep 16, 2021
This was referenced Oct 19, 2021
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.
Updates to DFA Matcher to avoid allocations in more cases. This makes
the matcher more pay-for-play.
First, avoid creating the RVD unless there are parameters or
constraints. This means that the candidate set can contain null route
value dictionaries. This seems fine because selectors are already
low-level. The route values feature will allocate an RVD when accessed,
so code in MVC or middleware won't even see a null RVD.
Secondly, avoid creating the candidate set unless there are selectors.
This will save an allocation most of the time since we won't need to run
selectors is really common cases. The candidate set is needed because
selectors mix mutability and async, so it needs to be a reference type.
However the default case is that we don't need to run selectors. The
impact of this is that we make a bunch of methods have an instance
variant and a static variant that operates on the array.
I ran some perf tests on this, and it helps the case where you have multiple endpoints that match but no policies. We don't have any tests that directly benchmark this scenario, but it's somewhat common when you use parameters and literals in the same position, or use constraints.
Numbers from
GithubMatcherBenchmark
- this benchmark has some cases like this, and there's a marginal improvement across the aggregate.Before
After