Skip to content

Conversation

@stephentoub
Copy link
Member

Description

MS.Internal.ContentType is incurring a multitude of unnecessary allocations. It's parsing input by Substring'ing along it and Trim'ing along it to find the next piece, but only a subset of those strings are actually saved. It's using string.Split just to get two strings, resulting in a string[]. Etc.

Customer Impact

Apps using this indirectly incur unnecessary overhead.

Regression

No

Testing

CI

Risk

Minimal.

The parsing logic involves a loop that repeatedly Substrings and Trims the remaining space.  We can change this to use spans and only create strings when they're actually needed to be stored; the other temporary slices don't need to allocate.
@stephentoub stephentoub requested a review from a team as a code owner March 17, 2022 13:33
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Mar 17, 2022
@ghost ghost requested review from SamBent, dipeshmsft and singhashish-wpf March 17, 2022 13:35
Comment on lines +528 to +529
int startingLength = ++length;
length = s.Slice(startingLength).IndexOf('"');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
int startingLength = ++length;
length = s.Slice(startingLength).IndexOf('"');
int startingLength = length + 1;
length = s.Slice(startingLength).IndexOf('"') + 1;

Copy link
Member Author

@stephentoub stephentoub Mar 18, 2022

Choose a reason for hiding this comment

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

That won't work correctly. We can change the ++length to be length + 1, but not the second line.

@dipeshmsft dipeshmsft merged commit 739d6d5 into dotnet:main May 5, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants