-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Conversation
@justinvp can you provide any data about how much this improves things? According to our contribution bar https://github.com/dotnet/coreclr/wiki/Contributing#contribution-bar we are only taking changes that have a demonstrably broad impact of a mainline scenario and are low risk. |
I don't have any data for this. I was investigating the possibility of optimizing |
Although minor improvement, it still counts IMO. |
605b8eb
to
508fbad
Compare
I updated the PR, removing the formatting & trailing whitespace cleanup, to make the changes more targeted. The diff is simpler and easier to review now. I also ran a microbenchmark for a contrived case where the count is 1 (10,000,000 iterations). The result was ~12x speed improvement, in addition to the allocation reduction.
|
@stephentoub, @ericstj, @janvorli, thoughts on this? |
Most impressive. 👍 |
@justinvp The benchmark you provided is not sufficient. The value of count is rarely 0 or 1. The more interesting benchmark would show the difference in perf when numReplaces > 0 and count > 1. We have to show that the perf of this path of execution is not degraded and we have to show that on different microarchitectures from Intel and AMD. Another benchmark with random input is also required. |
Agree.
Not possible, see https://github.com/dotnet/coreclr/issues/1078#issuecomment-107718404 and https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#building-the-repository. Interesting thoughts though. 😄 |
@jasonwilliams200OK Thanks for the references, but they are not related. x86 and x64 are ISAs, not microarchitectures which are totally different. |
@hadibrais, thanks for the correction. Now I understand that it was subjected to organization. |
@jasonwilliams200OK Yes that would be nice. |
@@ -973,17 +973,20 @@ internal String[] SplitInternal(char[] separator, int count, StringSplitOptions | |||
|
|||
if ((count == 0) || (omitEmptyEntries && this.Length == 0)) | |||
{ | |||
return new String[0]; | |||
return EmptyArray<String>.Value; |
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.
In theory I think this change to use a cached empty array is good. In practice I do worry about compat issues that could arise. If it were just for .NET Core, I'd be less concerned, and we've made many similar changes in corefx, but as this mscorlib is used elsewhere, I wonder if it's worth it, especially considering what I'd expect to be the relative rarity of hitting these cases (I could be wrong). @jkotas, any thoughts?
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.
how's about using a static readonly string[] which is conditionally compiled to either new string[0];
, and EmptyArray<string>.Value
?
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.
I would make the change to return EmptyArray.Value under #if FEATURE_CORECLR as @mburbea suggested. The change has likely marginal benefit - it is not worth discussing the compat risk on whether to take it everywhere.
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.
Thanks for the feedback. Updated to use #if FEATURE_CORECLR
.
- Use EmptyArray<String>.Value instead of new String[0] on .NET Core - Return early before allocating internal array(s) when count == 1
Thanks for the feedback. PR updated. I also verified the change doesn't regress perf when numReplaces > 0 and count > 1. |
LGTM. Have you tried running the corefx System.Runtime tests using this? Doesn't like there should be any issues, but it'd be good just to verify nothing pops. |
Yep, all corefx System.Runtime tests pass with these changes running locally on my machine. |
EmptyArray<String>.Value
instead ofnew String[0]
on .NET Corecount == 1