-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
PGO: Enable profiled casts by default #96597
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsThis PR enables PGO for Benchmark:IEnumerable<int> _enum1 = new int[10];
IEnumerable<int> _enum2 = new int[10];
[Benchmark]
public bool SequenceEqual() => _enum1.SequenceEqual(_enum2);
[Benchmark]
public int ElementAt() => _enum1.ElementAt(5);
[Benchmark]
public int Count() => _enum1.Count();
Codegen example// Promote IsList to Tier1 with PGO
for (int i = 0; i < 200; i++)
{
IsList(new int[10]); // source is always int[]
Thread.Sleep(10);
}
[MethodImpl(MethodImplOptions.NoInlining)]
bool IsList<T>(IEnumerable<T> source) => source is IList<T>; ; Assembly listing for method IsList
G_M12490_IG01:
sub rsp, 40
G_M12490_IG02:
+ mov rax, rcx
+ test rax, rax ; if (source == null)
+ je SHORT G_M12490_IG05
+G_M12490_IG03:
+ mov rdx, 0x7FF941DE9750
+ cmp qword ptr [rax], rdx
+ je SHORT G_M12490_IG05 ; if (source is int[])
+G_M12490_IG04:
mov rdx, rcx
mov rcx, 0x7FF942439A60
call CORINFO_HELP_ISINSTANCEOFINTERFACE ; slow fallback
+G_M12490_IG05:
test rax, rax
setne al
movzx rax, al
-G_M12490_IG03:
+G_M12490_IG06:
add rsp, 40
ret
; Total bytes of code 59 @AndyAyersMS do you think this should go through an internal run of dotnet/performance first?
|
/azp run runtime-coreclr pgo, runtime-coreclr libraries-pgo, runtime-coreclr pgostress |
Azure Pipelines successfully started running 3 pipeline(s). |
Thanks. If this is isinst/castclass only, I assume it doesn't cover a pattern like this? runtime/src/libraries/System.Linq/src/System/Linq/Enumerable.cs Lines 39 to 59 in 21b4a85
(or is that covered separately?) |
This code looks like it's already devirtualized by hands so there is nothing JIT can do additionally here. Although, you can convert it back to One benefit of |
It was written this way to explicitly avoid the variance costs |
PGO pipelines fail with #96612 (unrelated issue) |
As a follow up you might look at whether cloning can profitably key off of one of these casts. Right now type test cloning requires |
Ah good point, will file an issue for it! |
This PR enables PGO for
castclass/isinst
by default. Since we now have a dedicated tier for instrumentation it should not be a big deal to enable more probes IMO. Profiled casts seem to help LINQ for small inputs since LINQ is typically full of type casts for fast paths (e.g. this).Benchmark:
PS:
SequenceEqual
should benefit from #96571 tooCodegen example
Codegen diff (Main vs PR) for
IsList
:@AndyAyersMS @dotnet/jit-contrib do you think this should go through an internal run of dotnet/performance first?
I tested impact on TE (no impact on startup and rps) and a few desktop app. Also, I did a run of 250 LINQ benchmarks in dotnet/performance (10% of them improved, none regressed).