-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
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 SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issuePerformance related issue
Milestone
Description
From some discussion over in dotnet/csharplang#1085. Both the for and foreach cases have suboptimal CQ.
In the for case there is a redundant branch in the inner loop.
In the foreach case the enumerator's MoveNext is not inlined. If we force this and MoveNextRare inline then the jit is not able to optimize away the version check overhead in the inner loop.
Without the inlines the foreach is rougly 2.9x slower than the for; with the inlines this drops to 1.3x or so.
static int SumFor(List<int> l)
{
int result = 0;
for (int i = 0; i < l.Count; i++)
{
result += l[i];
}
return result;
}
static int SumForeach(List<int> l)
{
int result = 0;
foreach (int i in l)
{
result += i;
}
return result;
}category:cq
theme:basic-cq
skill-level:expert
cost:medium
impact:large
HFadeel, mattwarren, fanoI and adamkvd
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 SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issuePerformance related issue