Prevent closure allocations in OnHeartbeat (#1261)
This commit is contained in:
parent
7bdd98ea69
commit
8b44e8e382
|
|
@ -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> _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 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
|
// 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
|
// 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)
|
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(
|
_engine.Libuv.walk(
|
||||||
_loop,
|
_loop,
|
||||||
(ptr, arg) =>
|
callback,
|
||||||
{
|
arg
|
||||||
callback(ptr);
|
);
|
||||||
},
|
|
||||||
IntPtr.Zero);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PostCloseHandle(Action<IntPtr> callback, IntPtr handle)
|
private void PostCloseHandle(Action<IntPtr> callback, IntPtr handle)
|
||||||
|
|
@ -336,13 +344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
|
||||||
|
|
||||||
private void OnHeartbeat(UvTimerHandle timer)
|
private void OnHeartbeat(UvTimerHandle timer)
|
||||||
{
|
{
|
||||||
var now = Loop.Now();
|
Walk(_heartbeatWalkCallback, (IntPtr)Loop.Now());
|
||||||
|
|
||||||
Walk(ptr =>
|
|
||||||
{
|
|
||||||
var handle = UvMemory.FromIntPtr<UvHandle>(ptr);
|
|
||||||
(handle as UvStreamHandle)?.Connection?.Tick(now);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool DoPostWork()
|
private bool DoPostWork()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue