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

Perf regression on StringBuilder.Append #13107

Closed
Symbai opened this issue Jul 18, 2019 · 4 comments
Closed

Perf regression on StringBuilder.Append #13107

Symbai opened this issue Jul 18, 2019 · 4 comments
Assignees
Labels
Milestone

Comments

@Symbai
Copy link

Symbai commented Jul 18, 2019

There is a small performance regression comparing 2.2 vs 3.0 (10%), but a bigger regression comparing .NET Framework vs 3.0 (18%).

BenchmarkDotNet=v0.11.5, OS=Windows 10.0.18362
Intel Core i7-4960X CPU 3.60GHz (Haswell), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=3.0.100-preview8-013015
  [Host]     : .NET Core 3.0.0-preview8-27911-03 (CoreCLR 4.700.19.36002, CoreFX 4.700.19.36101), 64bit RyuJIT
  Job-EGUGMC : .NET Core 2.2.3 (CoreCLR 4.6.27414.05, CoreFX 4.6.27414.05), 64bit RyuJIT
  Clr        : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.8.3815.0
  Core       : .NET Core 3.0.0-preview8-27911-03 (CoreCLR 4.700.19.36002, CoreFX 4.700.19.36101), 64bit RyuJIT
Method Runtime Toolchain Mean Error StdDev
Small Core .NET Core 2.2 179.1 ns 0.7665 ns 0.5984 ns
Medium Core .NET Core 2.2 8,932.6 ns 25.0438 ns 22.2007 ns
Large Core .NET Core 2.2 876,877.0 ns 4,255.3692 ns 3,553.4260 ns
Small Clr Default 171.3 ns 0.3084 ns 0.2734 ns
Medium Clr Default 8,121.2 ns 17.6129 ns 14.7076 ns
Large Clr Default 805,701.2 ns 2,628.9582 ns 2,459.1291 ns
Small Core Default 188.3 ns 1.1118 ns 0.9284 ns
Medium Core Default 10,112.1 ns 40.8397 ns 38.2015 ns
Large Core Default 982,194.7 ns 3,529.5412 ns 3,128.8463 ns
[ClrJob]
[CoreJob]
[RPlotExporter]
public  class ObjectTest
{
    const string testString = "blablabla";
      
    [Benchmark]
    public bool Small()
    {
        var sb = new StringBuilder();
        for (int i = 0; i < 10; i++)
        {
            sb.Append(testString);
        }
        return sb.Length > 0;
    }
    [Benchmark]
    public bool Medium()
    {
        var sb = new StringBuilder();
        for (int i = 0; i < 1000; i++)
        {
            sb.Append(testString);
        }
        return sb.Length > 0;
    }
    [Benchmark]
    public bool Large()
    {
        var sb = new StringBuilder();
        for (int i = 0; i < 100000; i++)
        {
            sb.Append(testString);
        }
        return sb.Length > 0;
    }
}
@danmoseley
Copy link
Member

@adamsitnik in case he's interested

@danmoseley
Copy link
Member

cc @billwert

@danmoseley
Copy link
Member

@adamsitnik adamsitnik self-assigned this Oct 3, 2019
@adamsitnik
Copy link
Member

The source of the problem has been identified and now it's being tracked in dotnet/coreclr#27511 so I am closing this issue.

Moreover, I've also improved the performance of Append(char) so when dotnet/coreclr#27511 is implemented the .NET Core implementation is going to be actually faster (not just on par)

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants