Prevent closure allocations in OnHeartbeat (#1261)

This commit is contained in:
Pavel Krymets 2016-12-16 14:42:30 -08:00 committed by GitHub
parent 7bdd98ea69
commit 8b44e8e382
1 changed files with 14 additions and 12 deletions

View File

@ -23,6 +23,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
private static readonly Action<object, object> _postCallbackAdapter = (callback, state) => ((Action<object>)callback).Invoke(state);
private static readonly Action<object, object> _postAsyncCallbackAdapter = (callback, state) => ((Action<object>)callback).Invoke(state);
private static readonly Libuv.uv_walk_cb _heartbeatWalkCallback = (ptr, arg) =>
{
var handle = UvMemory.FromIntPtr<UvHandle>(ptr);
(handle as UvStreamHandle)?.Connection?.Tick((long)arg);
};
// maximum times the work queues swapped and are processed in a single pass
// as completing a task may immediately have write data to put on the network
@ -245,14 +250,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
}
public void Walk(Action<IntPtr> callback)
{
Walk((ptr, arg) => callback(ptr), IntPtr.Zero);
}
private void Walk(Libuv.uv_walk_cb callback, IntPtr arg)
{
_engine.Libuv.walk(
_loop,
(ptr, arg) =>
{
callback(ptr);
},
IntPtr.Zero);
callback,
arg
);
}
private void PostCloseHandle(Action<IntPtr> callback, IntPtr handle)
@ -336,13 +344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
private void OnHeartbeat(UvTimerHandle timer)
{
var now = Loop.Now();
Walk(ptr =>
{
var handle = UvMemory.FromIntPtr<UvHandle>(ptr);
(handle as UvStreamHandle)?.Connection?.Tick(now);
});
Walk(_heartbeatWalkCallback, (IntPtr)Loop.Now());
}
private bool DoPostWork()