Skip to content

Further reduce string allocations #32929

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 2 commits into from
May 25, 2021
Merged

Further reduce string allocations #32929

merged 2 commits into from
May 25, 2021

Conversation

pranavkm
Copy link
Contributor

Found a bunch of places that performed Substring and Split and replaced them with StringSegment. Didn't make a dent in the micro-benchmark but this feels like a low cost fix to consider.

@pranavkm pranavkm requested a review from Pilchie as a code owner May 22, 2021 02:30
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 22, 2021
@pranavkm pranavkm requested review from BrennanConroy and a team May 22, 2021 02:30
@pranavkm pranavkm force-pushed the prkrishn/more-allocations branch from 3813368 to 2232536 Compare May 22, 2021 02:31
{
@namespace = null;
return false;
}

relativePath = NormalizePath(relativePath);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NormalizePath turned \\ to /. But turns out we were later splitting on either path separators so we can safely remove it.

{
@namespace = null;
return false;
}

relativePath = NormalizePath(relativePath);
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mentioned this earlier, there's a Split that happens later on that tokenizes on either path separator and we only ever look at the path segments. The normalization is kinda moot.

@@ -568,6 +568,60 @@ public void IndexOf_SearchOnlyInsideTheRange_IfStartAndCountAreProvided()
Assert.Equal(-1, result);
}

[Fact]
Copy link
Member

Choose a reason for hiding this comment

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

Nit: let's add a note in StringSegment.cs to explain why we're rolling out our own implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a doc comment to the type.

@pranavkm pranavkm force-pushed the prkrishn/more-allocations branch 3 times, most recently from b8b246b to af9673d Compare May 24, 2021 22:57
@pranavkm pranavkm force-pushed the prkrishn/more-allocations branch from a669f97 to f93643b Compare May 24, 2021 23:01
@pranavkm
Copy link
Contributor Author

This has been updated.

@pranavkm pranavkm merged commit 1a2b326 into main May 25, 2021
@pranavkm pranavkm deleted the prkrishn/more-allocations branch May 25, 2021 22:21
@ghost ghost added this to the 6.0-preview6 milestone May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants