Skip to content
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

Cache ResponseCallback delegate in GrainReference to reduce allocs #2579

Merged
merged 1 commit into from
Jan 10, 2017

Conversation

ReubenBond
Copy link
Member

Until dotnet/roslyn#5835 is implemented, every grain call will currently perform 1 allocation for the response callback method group delegate.

This simply caches that in a static field.

    // [350 13 - 350 131]
    IL_0087: call         class Orleans.Runtime.IRuntimeClient Orleans.Runtime.RuntimeClient::get_Current()
    IL_008c: ldarg.0      // this
    IL_008d: ldarg.1      // 'request'
    IL_008e: ldloc.1      // resolver

// allocate for the method group
    IL_008f: ldnull       
    IL_0090: ldftn        void Orleans.Runtime.GrainReference::ResponseCallback(class Orleans.Runtime.Message, class [mscorlib]System.Threading.Tasks.TaskCompletionSource`1<object>)
    IL_0096: newobj       instance void class [mscorlib]System.Action`2<class Orleans.Runtime.Message, class [mscorlib]System.Threading.Tasks.TaskCompletionSource`1<object>>::.ctor(object, native int)

    IL_009b: ldarg.2      // debugContext
    IL_009c: ldarg.3      // options
    IL_009d: ldarg.0      // this
    IL_009e: ldfld        string Orleans.Runtime.GrainReference::genericArguments
    IL_00a3: callvirt     instance void Orleans.Runtime.IRuntimeClient::SendRequest(class Orleans.Runtime.GrainReference, class Orleans.CodeGeneration.InvokeMethodRequest, class [mscorlib]System.Threading.Tasks.TaskCompletionSource`1<object>, class [mscorlib]System.Action`2<class Orleans.Runtime.Message, class [mscorlib]System.Threading.Tasks.TaskCompletionSource`1<object>>, string, valuetype Orleans.CodeGeneration.InvokeMethodOptions, string)
    IL_00a8: nop   

Becomes

    // [352 13 - 352 139]
    IL_0087: call         class Orleans.Runtime.IRuntimeClient Orleans.Runtime.RuntimeClient::get_Current()
    IL_008c: ldarg.0      // this
    IL_008d: ldarg.1      // 'request'
    IL_008e: ldloc.1      // resolver

// No allocations, just a static field reference
    IL_008f: ldsfld       class [mscorlib]System.Action`2<class Orleans.Runtime.Message, class [mscorlib]System.Threading.Tasks.TaskCompletionSource`1<object>> Orleans.Runtime.GrainReference::ResponseCallbackDelegate

    IL_0094: ldarg.2      // debugContext
    IL_0095: ldarg.3      // options
    IL_0096: ldarg.0      // this
    IL_0097: ldfld        string Orleans.Runtime.GrainReference::genericArguments
    IL_009c: callvirt     instance void Orleans.Runtime.IRuntimeClient::SendRequest(class Orleans.Runtime.GrainReference, class Orleans.CodeGeneration.InvokeMethodRequest, class [mscorlib]System.Threading.Tasks.TaskCompletionSource`1<object>, class [mscorlib]System.Action`2<class Orleans.Runtime.Message, class [mscorlib]System.Threading.Tasks.TaskCompletionSource`1<object>>, string, valuetype Orleans.CodeGeneration.InvokeMethodOptions, string)
    IL_00a1: nop          

@sergeybykov sergeybykov merged commit 70dbbc0 into dotnet:master Jan 10, 2017
@ReubenBond ReubenBond deleted the reduce-allocs branch January 10, 2017 21:27
@ReubenBond ReubenBond added area-performance All performance related issues and removed performance labels Mar 24, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-performance All performance related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants