-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone
Description
The overall codegen for multi-dimensional arrays is poor and has worse performance than a jagged array, even though the former is linear in memory.
This has resulted in multiple StackOverflow posts on the topic and even Unity recommending that multi-dimensional arrays not be used: https://docs.unity3d.com/2019.3/Documentation/Manual/BestPracticeUnderstandingPerformanceInUnity8.html
It looks like there are a few obvious issues that should hopefully be trivially handled:
- The
Array.GetLength()method currently generates fairly unoptimal code. It actually winds up as a call rather than just a lookup to the underlying array data. Ideally these would be straight lookups when the dimension being looked up is constant and definitely in bounds of the rank. - The JIT doesn't appear to be eliding bounds checks against
Array.GetLength(), whether cached or otherwise - The JIT doesn't recognize that
for (y = 0; y < yLength; y++) { for (x = 0; x < xLength; x++) { data[x, y]; } }results in linear access of the underlying data
category:cq
theme:md-arrays
skill-level:expert
cost:large
GSPP and breadnonehiradyazdan, Sergio0694 and RekkonnectSergio0694
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Type
Projects
Status
Done