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

JIT: Unroll more Equals/StartsWith/EndsWith on arm64 #109036

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Oct 18, 2024

Seems like it's quite beneficial even on large sizes, at least on arm64:

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

public class Bench
{
    string s = "https://pkgs.dev.azure.com/dnceng/public/packaging/dotnet10/";

    [Benchmark]
    public bool Bestcase() => 
        s.StartsWith("https://pkgs.dev.azure.com/dnceng/public/pack", StringComparison.Ordinal);
    
    [Benchmark]
    public bool Bestcase_IgnoreCase() => 
        s.StartsWith("https://pkgs.dev.azure.com/dnceng/public/pack", StringComparison.OrdinalIgnoreCase);

    // Worst case: differs at 1st char:

    [Benchmark]
    public bool Worstcase() => 
        s.StartsWith("Xttps://pkgs.dev.azure.com/dnceng/public/pack", StringComparison.Ordinal);
    
    [Benchmark]
    public bool Worstcase_IgnoreCase() => 
        s.StartsWith("Xttps://pkgs.dev.azure.com/dnceng/public/pack", StringComparison.OrdinalIgnoreCase);
}
BenchmarkDotNet v0.14.0, Ubuntu 24.04 LTS (Noble Numbat)
Arm64
  Job-NEWBNL : .NET 10.0.0 (42.42.42.42424), Arm64 RyuJIT AdvSIMD
  Job-LSVZLO : .NET 10.0.0 (42.42.42.42424), Arm64 RyuJIT AdvSIMD
EnvironmentVariables=DOTNET_JitDisasm=Bestcase_IgnoreCase
Method Toolchain Mean Error Ratio
Bestcase Main 4.1458 ns 0.0071 ns 1.00
Bestcase PR 0.6151 ns 0.0007 ns 0.15
Bestcase_IgnoreCase Main 5.9848 ns 0.1685 ns 1.00
Bestcase_IgnoreCase PR 1.5489 ns 0.0044 ns 0.26
Worstcase Main 1.7136 ns 0.0003 ns 1.00
Worstcase PR 0.6572 ns 0.0013 ns 0.38
Worstcase_IgnoreCase Main 2.5230 ns 0.0015 ns 1.00
Worstcase_IgnoreCase PR 1.2213 ns 0.0016 ns 0.48

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 18, 2024
@EgorBo
Copy link
Member Author

EgorBo commented Oct 19, 2024

@MihuBot

@EgorBo
Copy link
Member Author

EgorBo commented Oct 19, 2024

@EgorBot -arm64 --envvars DOTNET_JitDisasm:Bestcase_IgnoreCase

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

public class Bench
{
    string s = "https://pkgs.dev.azure.com/dnceng/public/packaging/dotnet10/";

    [Benchmark]
    public bool Bestcase() => 
        s.StartsWith("https://pkgs.dev.azure.com/dnceng/public/pack", StringComparison.Ordinal);
    
    [Benchmark]
    public bool Bestcase_IgnoreCase() => 
        s.StartsWith("https://pkgs.dev.azure.com/dnceng/public/pack", StringComparison.OrdinalIgnoreCase);

    // Worst case: differs at 1st char:

    [Benchmark]
    public bool Worstcase() => 
        s.StartsWith("Xttps://pkgs.dev.azure.com/dnceng/public/pack", StringComparison.Ordinal);
    
    [Benchmark]
    public bool Worstcase_IgnoreCase() => 
        s.StartsWith("Xttps://pkgs.dev.azure.com/dnceng/public/pack", StringComparison.OrdinalIgnoreCase);
}

@EgorBo
Copy link
Member Author

EgorBo commented Oct 20, 2024

@MihuBot -arm -dependsOn 108838

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant