-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Avoid string.Split allocations in FrameworkName #7288
Conversation
|
BTW, I intentionally held back on optimizing out the initial allocation that called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using SubstringTrim from Common/src/System/StringExtensions.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not already in use in this assembly, I don't think it's worth the extra code being included. FrameworkNames aren't instantiated very often, are they? And if they are, are they instantiated with inputs that would cause these Trims to actually trim something? (Trim already returns the original string if there's nothing to trim.)
|
LGTM. Can you please squash this (or at least the first four commits)? |
|
@stephentoub Done. |
|
test innerloop osx release build and test |
|
Thanks, @jamesqo. |
|
Good work! |
|
@hughbe, how? |
|
I took a more detailed look at the PR and the String.Split code - that's not really necessary here actually, so nevermind! |
|
It's not a question of "necessary", but rather "possible". What optimization for String.Split did you have in mind? |
Avoid string.Split allocations in FrameworkName Commit migrated from dotnet/corefx@1c0df54
When parsing the input in the
FrameworkNameconstructor, we're expecting it to look something like this:The way we handle this is by calling
input.Split(','), and then splitting each of the individual components again viacomponent.Split('='). This is less than optimal, since callingSplitmakes 3 unneeded allocations:paramsarrayint[]that contains the separator indicesstring[]This PR replaces such use of
Splitwith the following snippet, eliminating these allocations:Other changes:
=signs.nameof.string.Format-> string interpolation.Related CoreCLR PR: dotnet/coreclr#3949
cc @AlexGhiondea @JonHanna @stephentoub