-
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
Multidimensional array performance #5481
Comments
Comparing the performance of various array representations is complex and depends on a lot of workload specifics. I won't attempt to spend time to cover it in this thread. But for this specific example, each implementation should each largely be able to perform the same speed for the specific dimensions sizes. I'm going to use this issue to cover what is missing work in RyuJIT handling rectangular arrays to match .NET 4.5.3 (JIT64) performance for the sum(double[,], d) method. Timings with RyuJIT: Timings with JIT64: The main reason for the deficiency is the failure of the d[I,..] calculation to be hoisted out of the inner loop, the array reference only varies on the inner-most dimension
The internal representation of the rectangular array is done through the arrMD&[] operator and is not decomposed until the Lower phase which runs after the global and loop optimizers. It is only some of these individual addressing calculations that are invariant, but not the entire operator hence it cannot be fully optimized unless it is lowered earlier. From the dumps you can see this happening during the Lowering phase in lowerxarch:
The work item here is to move the rectangular array lowering to run before the optimizer so that the invariant components of the array calculation are exposed to invariant code motion. There may be additional work in invariant code motion to properly hoist the arrMDIdx operator correctly. |
Is this still an issue in dotnet core 3? If so is there a process I can follow to get it triaged/tagged appropriately? Thanks. |
The benchmark is inaccurate for Release mode. What is actually slow is the call to Release with
Release with constant 1024x1024
Multidimensional array access is still considerably slower in Debug mode even with that change, though. |
This is addressed in #70271. There are follow-up items there to continue to improve MD array performance. |
There appears to be a long running issue with the performance of multidimensional arrays compared to a comparable jagged array. Are there any plans to look into this?
Some existing discussion here:
http://stackoverflow.com/questions/468832/why-are-multi-dimensional-arrays-in-net-slower-than-normal-arrays
http://stackoverflow.com/questions/5476000/c-multi-dimensional-array-vs-one-dimensional
I ran a quick test using .Net 4.6.1 in x64 mode (i.e. using ryuJIT), and the issue appears to still be present.
category:cq
theme:md-arrays
skill-level:expert
cost:large
The text was updated successfully, but these errors were encountered: