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

OR: performance tune Match function [PLAT-23274] #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jackmott
Copy link

Hi there!

Thank you so much for contributing this pull request. We love when the community
steps up and share, and we're enormously thankful.

You don't have to do all of those following things, they are what we try and get
done for code coming in:

  • the code
  • If it's a non-trivial piece of code, signing a CLA
  • If it breaks, change, fix or add to existing behaviour, updating
    CHANGELOG.md
  • If it's a bug fix, tests in the Tests project, or scenarios in the TestRig.
  • On top of HEAD, unless it's a bugfix on a previous version
  • VERSION file updated if not creating a pull-request on top of master

If those are needed, and you haven't and can't, we thank you enormously for your
contribution, and we'll add those before merging the pull request.

Thanks!

The OpenRasta community

@jackmott
Copy link
Author

jackmott commented Feb 14, 2020

Some Perf stats on this change:
Calling UriTemplateTabel.Match:

Gen0 collections collections completely eliminated
Total Allocated bytes reduce 66%
Time reduced by 58%


var cullCount = 0;
foreach (var baseUriSegment in baseSegments)
if (RemoveTrailingSlash(baseUriSegment) == candidateSegments[cullCount])
Copy link
Member

Choose a reason for hiding this comment

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

Could the RemoveTrailingSlash call be moved into the UriTemplateTable.Match() method here so that we don't need to trim each segment for each possible UriTemplate instance?

Copy link
Member

Choose a reason for hiding this comment

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

Additionally, could the RemoveTrailingSlash call be simplified to just baseUriSegment.TrimEnd('/')?

public Collection<UriTemplateMatch> Match(Uri uri)
{
var lastMaxLiteralSegmentCount = 0;
var matches = new Collection<UriTemplateMatch>();
foreach (var template in KeyValuePairs)
if (BaseAddress != null)
Copy link
Member

Choose a reason for hiding this comment

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

If I'm reading this right, if BaseAddress is null then no URL will ever find a match. Should BaseAddress be validated to not be null when initializing the UriTemplateTable instance?

{
case SegmentType.Literal when
string.CompareOrdinal(candidateSegment.ProposedSegment.Text, candidateSegment.UnescapedText) != 0:
string.CompareOrdinal(_segments[i].Text, unescapedText) != 0:
Copy link
Member

Choose a reason for hiding this comment

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

Not your code but this could be simplified to !string.Equals(_segments[i].Text, unescapedText, StringComparison.OrdinalIgnoreCase).

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

Successfully merging this pull request may close these issues.

2 participants