-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
ReadOnlySpan<char>.Trim for small inputs is few times slower on Linux #13669
Comments
As it so happens I already have a fix for this in a local branch. Assigning to self. Edit: My fix involved improving |
The general fix is to better take advantage of the SysV calling conventions for structs. This is especially notable for benchmarks that pass small-length spans (see eg #12901) as the method called tends not to do much work, so the calling overhead stands out. cc @CarolEidt |
Is it worthwhile to improve the performance of the |
@AndyAyersMS @CarolEidt It looks like JIT knows how pass the structs by readonly reference on Linux when we tell it explictilty to do so. Is it "just" a matter of tuning the heuristic which decides when to pass the struct by reference? I've done some more profiling today and I've observed this problem in more places. I think we should consider fixing it for 5.0. |
@kevingosse @mjsabby have you ever seen |
@GrabYourPitchforks I wonder if it would be possible to have only one |
It has zero hits in the Azure telemetry. |
Never noticed it, but we don't make a heavy usage of Span. In our applications it's only used by corefx and aspnetcore. |
The only thing showing up around span is |
@ezsilmar thank you very much! |
The struct values passed to |
Fixed by #43870 |
@CarolEidt awesome! can't wait to see how many benchmarks show improvement on Linux FWIW these 3 charts should show it for this particular method in the next 24 hours: 1, 2, 3 |
ReadOnlySpan<char>.Trim
for small inputs is few times slower on LinuxBenchmark:
https://github.com/dotnet/performance/blob/8b23cabe793b4ff73a9b28c7dd092b11dc17b197/src/benchmarks/micro/corefx/System.Memory/ReadOnlySpan.cs#L77-L79
I've created a very small repro app:
And using VTune I was able to narrow down the problem to struct copying:
The body of the
Main
method on Ubuntu 18.04:Please mind the body of the loop:
When I change
TrimSourceCopied
to accept theSpan
asreadonly ref
parameter:System.Memory.ReadOnlySpan.Trim
is only one example of a benchmark that usesSpan
a lot and is slower on Linux compared to Windows. This pattern|problem is quite common./cc @AndyAyersMS
category:cq
theme:structs
skill-level:expert
cost:medium
The text was updated successfully, but these errors were encountered: