Remove several Timer-related allocations from CancellationTokenSource (dotnet/coreclr...
authorStephen Toub <stoub@microsoft.com>
Mon, 22 Oct 2018 18:27:05 +0000 (11:27 -0700)
committerGitHub <noreply@github.com>
Mon, 22 Oct 2018 18:27:05 +0000 (11:27 -0700)
commit7b48019ee907d4de1cc66169c53315aaa287a71d
treed7ba37e84c77514eaefd544b370669967a5de304
parent7460637f0ff186b3a9cfd0f53957da09f55f619c
Remove several Timer-related allocations from CancellationTokenSource (dotnet/coreclr#20509)

When CancellationTokenSource creates a Timer, it passes itself as state, which then results in the Timer being rooted while it's scheduled.  As such, the Timer object itself and the TimerHolder object it creates are largely irrelevant, and since CancellationTokenSource has access, it can just create the underlying TimerQueueTimer object directly.  This means that every CTS that creates a Timer now creates two fewer objects, one of which was finalizable.

Commit migrated from https://github.com/dotnet/coreclr/commit/628df3872905496e12a8252da7eb7731c05be4b4
src/coreclr/src/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs