Skip to content
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 Pattern matching allocations #1590

Merged
merged 5 commits into from
Jul 31, 2017

Conversation

benaadams
Copy link
Contributor

@benaadams benaadams commented Jul 28, 2017

Saves 8,292 MB on delete roslyn\Binaries\Obj + run nuget restore Roslyn.sln -NoCache

Resolves NuGet/Home#5668 (Except SubStrings used for TokenSegment)
Resolves NuGet/Home#5665 (Except TokenSegment.TryMatch calls string.Substring)
Contributes to NuGet/Home#5664 (PatternExpression.Match)

@sharwell is this more what you meant? Specifically benaadams@3dac48b

@dnfclas
Copy link

dnfclas commented Jul 28, 2017

@benaadams,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

@benaadams
Copy link
Contributor Author

Has issues

@benaadams benaadams force-pushed the PatternExpression.Initialize branch from 3dac48b to 3f7163c Compare July 30, 2017 22:44
@benaadams
Copy link
Contributor Author

Missed an ! out O_o

@benaadams
Copy link
Contributor Author

Saves 8,292 MB on delete roslyn\Binaries\Obj + run nuget restore Roslyn.sln -NoCache

@emgarten
Copy link
Member

@benaadams is this working for you now? I can re-run the tests on this branch

@benaadams
Copy link
Contributor Author

benaadams commented Jul 30, 2017

Yes; I'd missed a not sign before, rookie mistake - hours to track down.


public Dictionary<string, object> Properties
{
get => _properties ?? CreateDictionary();
Copy link

@MarcinJuraszek MarcinJuraszek Jul 30, 2017

Choose a reason for hiding this comment

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

Why not get => _properties ?? (_properties = new Dictionary<string, object>());? I think that's a quite common pattern. Or would that make the getter too big to get inlined later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@halter73 told me off for doing that once; now is habit 😄

Smaller for inline without the new; though unlikely to be significant.

Choose a reason for hiding this comment

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

I guess every repo/team/project has different guidelines :) I was just curious if there is a reason not to use the pattern I personally find quite nice.

Copy link
Member

@emgarten emgarten left a comment

Choose a reason for hiding this comment

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

LGTM

@emgarten
Copy link
Member

✔️ all tests are passing for this branch

Thanks for the fix @benaadams! These patterns get hit going through every file from every nupkg during restore, this will be a great improvement 🚀

@emgarten emgarten merged commit 116b7a8 into NuGet:dev Jul 31, 2017
@@ -144,6 +142,21 @@ public virtual bool TryLookup(string name, PatternTable table, out object value)
return false;
}

private static bool ContainsSlash(string name)
Copy link
Contributor

Choose a reason for hiding this comment

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

What are we saving here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IndexOfAny with a char array is a multi stage process where it first creates a probabilistic map then scans for possible matches before checking for actual match. Which ends up being a little overkill for just 2 item arrays; and its faster just to check for the two chars.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Came across when looking into a perf issue with MVC; which was also 2 delimiters aspnet/Mvc#5362

Copy link
Contributor

Choose a reason for hiding this comment

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

Did we get a bug on this? If not, I'm going to file one - I'm seeing the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope never filed anything; was when I was working exclusively upstream; before I got caught by the slippery slope and started contributing to coreclr

Copy link
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants