-
Notifications
You must be signed in to change notification settings - Fork 686
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
Reduce allocations in TokenSegment.TryMatch #5933
Merged
Merged
Conversation
This file contains 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
8 tasks
7a782d3
to
6c5f8cc
Compare
I got a couple of changes that depend on this one, so if anyone's not focusing on somethig unrelating, this would be a great PR to review :) |
jeffkl
previously approved these changes
Jul 30, 2024
zivkan
reviewed
Jul 30, 2024
src/NuGet.Core/NuGet.Packaging/ContentModel/ContentPropertyDefinition.cs
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Packaging/ContentModel/ReadOnlyMemoryCharComparerOrdinal.cs
Outdated
Show resolved
Hide resolved
....Core.Tests/NuGet.Packaging.Test/ContentModelTests/ReadOnlyMemoryCharComparerOrdinalTests.cs
Outdated
Show resolved
Hide resolved
dtivel
reviewed
Jul 30, 2024
src/NuGet.Core/NuGet.Packaging/ContentModel/ReadOnlyMemoryCharComparerOrdinal.cs
Outdated
Show resolved
Hide resolved
6c5f8cc
to
93bfaae
Compare
zivkan
approved these changes
Jul 31, 2024
zivkan
reviewed
Jul 31, 2024
src/NuGet.Core/NuGet.Packaging/ContentModel/ReadOnlyMemoryCharComparerOrdinal.cs
Show resolved
Hide resolved
jeffkl
reviewed
Jul 31, 2024
dtivel
approved these changes
Jul 31, 2024
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.
Bug
Related: NuGet/Home#12728
Also internal workitem.
Regression? Last working version:
Description
This uses
ReadOnlyMemory<char>.Slice()
instead ofstring.Substring()
to reduce allocations when pattern matching. This also needs to cache the matches with aDictionary<ReadOnlyMemory<char>, object>
inPatternTable
so I needed to re-use an ordinal comparer that I found in another repo. The rest of the changes are fallout from changing the pattern we're looking for from astring
toReadOnlyMemory<char>
. The reason I'm usingReadOnlyMemory<T>
instead ofReadOnlySpan<T>
is thatReadOnlySpan<T>
is areadonly ref struct
and can't be used as a type parameter.I had to change the public API of
NuGet.ContentModel.ContentPropertyDefinition
andNuGet.ContentModel.PatternTable.TryLookup
. I'm not sure how widely those are used by anyone so I marked the associated issue as a "breaking change" just to be safe.This PR:
17.11 P3
3 runs each, on average, it's about 10MB for OrchardCore.
1/3 runs were a bit noisy and showing similar results.
Dictionary is the same amount of allocations, no substring allocations.
TryLookup is worse because of the ToString actualizations. A bit of a trade-off.
Note
This PR is not the last PR in this space.
PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation