-
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
JIT: Inline static readonly delegates #85803
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue Detailsstatic Func<int, int, int> MyFunc { get; } = (x, y) => x + y;
static int Test() => RunFunc(MyFunc);
static int RunFunc(Func<int, int, int> processor)
{
return processor(10, 20);
} codegen for ; Assembly listing for method Program:Foo():int
; Tier-1 compilation
mov eax, 30
ret
; Total bytes of code 6 Not sure it's super useful (how often developers save delegates to static readonly?) but it's a first case when we can inline a lambda without checks 🙂
|
This is quite common. However it's much less common to invoke the delegate directly from that field... the primary use is passing it off to another method that will then invoke it, and that method is often not going to be inlined. |
Ah so do we need this? 🙂 The PR should be fully complete, it's just that it's +100 LOC and needs tests, I extracted TypeHandle part into a separate PR |
My gut is it won't help much. But if there's an easy way to see how often it would kick in across runtime, for example, I'd be happy to be proven wrong. |
I need both of the changes. Thanks! |
Can you comment on where on hot paths you directly invoke delegates stored in static readonly fields? Thanks. |
It was the case I was loading and compiling simple text expressions into delegates, which were then used directly as filters and calculated fields, or in implementations of other filters. |
codegen for
Test()
with PGO enabled:Not sure it's super useful (how often developers save delegates to static readonly?) but it's the first case when we can inline a lambda without checks 🙂
UPD: Also, it seems to fold
typeof(T).TypeHandle.Value;
and closes #5973codegen: