-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
MemoryStream.Write() slow on Ryzen CPUs #13009
Comments
Additional benchmark data from a machine with a Ryzen 1600X. Same characteristics:
|
May not be strictly related to Ryzen - I've managed to reproduce on a Xeon (albeit running inside a VM):
|
Is it possible to show a comparison of 2.1 and 3.0? |
Re-ran on Ryzen 1200 using 3.0 - I can run on the Intel machines later if required.
|
Got a new CPU (Ryzen 3600) recently and .NET 4.7.2 runs considerably faster, but Core 3.0 runs even slower:
|
Perhaps @tannergooding has thoughts. |
I am just about to refresh my private PC with Ryzen 3600, so unless someone beats me on that, I can look into it once I have the new machine set up. I expects that to happen in about two weeks. |
I'll profile on my 1800X when I get into the office. I'll be getting a 3900X in a few days and can test on that then as well. |
After investigating, almost the entire time for both .NET Core and full framework is being spent in a |
Looks like this was changed in dotnet/coreclr#7198 |
Interesting, I was almost sure it will be that :-). |
It would be interesting to try if changing the rep movsb cutoff that's set to 512 bytes would help Ryzen to perform better. |
I'll give that a try. Also going to grab perf metrics using the CRT implementation method. |
Reverting to use the CRT implementation makes it the same speed as .NET Framework (it actually looks to be consistently about 1% faster, but that is likely within error). Changing the As @jkotas called out in the original PR (dotnet/coreclr#7198 (comment)), having a private copy of I would be very much in favor of removing this path, especially since it causes a nearly 2x slowdown on Ryzen machines. It is also missing a bunch of logic around prefetching, ensuring data alignment, etc that the CRT implementation does currently have. |
@jkotas, @janvorli. I this something we should consider fixing for 3.0, considering it is a nearly 2x penalty for copying memory on Ryzen CPUs? The fix is relatively trivial, removes us having a custom memcpy routine (which is already 64-bit Windows only), and won't significantly regress Intel CPUs (based on the numbers in the original PR, it was 33% average for inputs under 512 bytes and no real difference for inputs over 512 bytes). |
In any case, you should submit a fix to master for .NET 5. We can then decide whether it will get backported to release/3.0. |
I put up dotnet/coreclr#25750 to resolve the issue for .NET 5 |
I've noticed while doing some benchmarking that .NET Core is noticeably (21%) slower than .NET Framework on my AMD Ryzen 1200 based PC for a certain piece of code.
Running the same benchmark on an Intel i7 6700 based PC shows .NET Core running significantly (41%) faster than Framework.
Code to reproduce is here:
https://github.com/LordBenjamin/DotNetCore-Ryzen-Performance-Repro/
Benchmarks
OriginalBenchmark.cs
Quite close to my actual code. Slower on Ryzen and faster on Intel.
StreamWriteBenchmark.cs
Distilled down after I noticed that commenting out the call to
MemoryStream.Write(byte[] buffer, int offset, int count);
inOriginalBenchmark.cs
leaves .NET Core consistently faster on both CPUs. Core performance is significantly worse on Ryzen, but comparable to Framework on Intel.Affected Frameworks
I can reproduce using both .NET Core 2.1 and 3.0. Framework version is 4.7.2 in both cases.
Results
Happy to supply further information or change and re-run benchmarks as required.
The text was updated successfully, but these errors were encountered: