You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[macOS] Potential regression in delegates invocation #59152
@AndyAyersMS - Is this the example that involves struct arguments passing and we hit some struct promotion limit that you were referring to few days back?
As far as investigating goes, we should see if we can repro locally, then we can drill in (perhaps start with jitted codegen for the benchmark method).
@AndyAyersMS it was reproducible on all three x64 mac books that we have used (mine is 4 year old mac book pro, not sure about @jeffhandley or @carlossanlop laptops who provided the other results).
I need to redirect this back to you for initial investigation per Andy's comments.
I am able to reproduce it on my macBook, the problem is that there is no easy way to get disassembly on macOS so I can't just share it. That is why it would be better if someone from the JIT Team took a look at this.
Thanks, @AndyAyersMS. Unless you think this should be considered for 6.0.1 (first servicing release) as a potential issue to address, it's not urgent. Since it can be repro'd, I'll remove the needs further triage label.
From what I can tell the jitted codegen for 5.0 and 6.0 is identical. So the perf issue is either in the native part of the runtime (seems unlikely) or some stub I can't yet see, or...?
Going to try and get a more general profile, but I am not that familiar with how to do this on MacOS.
In 5.0 we only 32 byte aligned Tier1 methods with loops. This was fixed in 6.0 (#42909) to handle 32 byte aligning all optimized method with loops. We later went on to add alignment padding for loops in 6.0. But we bypass padding if a loop contains a call.
In this test the jitted codegen is identical in 5.0 and 6.0, and the key inner loop in InvokeDelegate is
For 6.0 the method is 32 byte aligned, and so this loop body runs from 0x3E .. 0x6A and needs 3 fetch windows (plus presumably one more for the call).
For 5.0 the method ends up being 16 byte aligned, this is favorable for the key loop which now spans (effectively) 0x2E..0x5A or two fetch windows (plus perhaps one more for the call).
But if I fix the "bug" in the 5.0 alignment code by setting COMPlus_TC_QuickJitForLoops=1 then 5.0 also gets 32 byte method alignment and so poor loop alignment, and the performance equalizes:
If you modify the benchmark to use a param instead of a static for the loop limit InnerIterationCount200000 we see similar swings in perf, as removing the class init check modifies the loop alignment.
At any rate, here's a case where aligning a loop with a call seems to have a noticeable impact on perf, because the callee is trivial.
From the above we can see 5.0 is consistently fastest, with 6.0 or 7.0 sometimes similar to 5.0 and sometimes slower depending on the particular processor. 7.0 is generally faster than 6.0 though not always.
I modified the jit to align small (single block) loops with calls (as in the benchmark) and didn't see any improvement, so at this point I suspect the perf differences are related to the alignment of the delegate or its precode.
I think this sort of thing is only going to show up prominently when we have frequently executed delegates that do little or no computation. So, I'm going to close this as won't fix.
Activity
jeffhandley commentedon Sep 30, 2021
@AndyAyersMS @kunalspathak @EgorBo What would you recommend as the first step of investigating this?
kunalspathak commentedon Sep 30, 2021
@AndyAyersMS - Is this the example that involves struct arguments passing and we hit some struct promotion limit that you were referring to few days back?
AndyAyersMS commentedon Sep 30, 2021
I don't think so -- the test doesn't look like it involves structs.
https://github.com/dotnet/performance/blob/d7dac8a7ca12a28d099192f8a901cf8e30361384/src/benchmarks/micro/runtime/perflab/DelegatePerf.cs#L32-L44
As far as investigating goes, we should see if we can repro locally, then we can drill in (perhaps start with jitted codegen for the benchmark method).
What HW was this...?
jeffhandley commentedon Oct 7, 2021
@adamsitnik I need to redirect this back to you for initial investigation per Andy's comments.
adamsitnik commentedon Oct 11, 2021
@AndyAyersMS it was reproducible on all three x64 mac books that we have used (mine is 4 year old mac book pro, not sure about @jeffhandley or @carlossanlop laptops who provided the other results).
I am able to reproduce it on my macBook, the problem is that there is no easy way to get disassembly on macOS so I can't just share it. That is why it would be better if someone from the JIT Team took a look at this.
jeffhandley commentedon Oct 11, 2021
My MacBook Pro is a mid-2014 13" retina with 2.6GHz dual-core Intel Core i5 and 8GB RAM.
5 remaining items
AndyAyersMS commentedon Oct 19, 2021
I can repro this. Will see what I can uncover...
jeffhandley commentedon Oct 19, 2021
Thanks, @AndyAyersMS. Unless you think this should be considered for 6.0.1 (first servicing release) as a potential issue to address, it's not urgent. Since it can be repro'd, I'll remove the needs further triage label.
AndyAyersMS commentedon Oct 25, 2021
From what I can tell the jitted codegen for 5.0 and 6.0 is identical. So the perf issue is either in the native part of the runtime (seems unlikely) or some stub I can't yet see, or...?
Going to try and get a more general profile, but I am not that familiar with how to do this on MacOS.
AndyAyersMS commentedon Oct 25, 2021
Ok, think this is related to loop alignment.
In 5.0 we only 32 byte aligned Tier1 methods with loops. This was fixed in 6.0 (#42909) to handle 32 byte aligning all optimized method with loops. We later went on to add alignment padding for loops in 6.0. But we bypass padding if a loop contains a call.
In this test the jitted codegen is identical in 5.0 and 6.0, and the key inner loop in
InvokeDelegateisFor 6.0 the method is 32 byte aligned, and so this loop body runs from 0x3E .. 0x6A and needs 3 fetch windows (plus presumably one more for the call).
For 5.0 the method ends up being 16 byte aligned, this is favorable for the key loop which now spans (effectively) 0x2E..0x5A or two fetch windows (plus perhaps one more for the call).
As a result 5.0 runs faster:
But if I fix the "bug" in the 5.0 alignment code by setting
COMPlus_TC_QuickJitForLoops=1then 5.0 also gets 32 byte method alignment and so poor loop alignment, and the performance equalizes:If you modify the benchmark to use a param instead of a static for the loop limit
InnerIterationCount200000we see similar swings in perf, as removing the class init check modifies the loop alignment.At any rate, here's a case where aligning a loop with a call seems to have a noticeable impact on perf, because the callee is trivial.
cc @kunalspathak
AndyAyersMS commentedon Apr 25, 2022
We should revisit this now that OSR is enabled and see what that does (will wait for the 7P4 perf runs...)
AndyAyersMS commentedon Jun 16, 2022
Current data with 7.0 looks better but still not quite as good as 5.0
AndyAyersMS commentedon Jul 13, 2022
Procrastination not paying off here. 7p6 is not any faster.
BenchmarkDotNet=v0.13.1.1786-nightly, OS=macOS Monterey 12.4 (21F79) [Darwin 21.5.0]
Intel Core i5-4278U CPU 2.60GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
.NET SDK=7.0.100-preview.6.22352.1
[Host] : .NET 7.0.0 (7.0.22.32404), X64 RyuJIT
Job-SVXENR : .NET 5.0.11 (5.0.1121.47308), X64 RyuJIT
Job-AZCEHU : .NET 6.0.6 (6.0.622.26707), X64 RyuJIT
Job-XJBOAY : .NET 7.0.0 (7.0.22.32404), X64 RyuJIT
PowerPlanMode=00000000-0000-0000-0000-000000000000 IterationTime=250.0000 ms MaxIterationCount=20
MinIterationCount=15 WarmupCount=1
AndyAyersMS commentedon Jul 13, 2022
FWIW TieredPGO does nicely here in .NET 7, thanks to @jakobbotsch
AndyAyersMS commentedon Jul 13, 2022
Some non-OSX data on Intel CPUs
PowerPlanMode=00000000-0000-0000-0000-000000000000 IterationTime=250.0000 ms MaxIterationCount=20
MinIterationCount=15 WarmupCount=1
AndyAyersMS commentedon Jul 15, 2022
From the above we can see 5.0 is consistently fastest, with 6.0 or 7.0 sometimes similar to 5.0 and sometimes slower depending on the particular processor. 7.0 is generally faster than 6.0 though not always.
I modified the jit to align small (single block) loops with calls (as in the benchmark) and didn't see any improvement, so at this point I suspect the perf differences are related to the alignment of the delegate or its precode.
I think this sort of thing is only going to show up prominently when we have frequently executed delegates that do little or no computation. So, I'm going to close this as won't fix.