Skip to content

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented Jun 23, 2021

Description

Every time DispatcherTimer.Restart is called (which may happen on every tick), it's allocating a new delegate to point to the instance's FireTick method. We can instead make it a non-capturing delegate, such that the compiler caches it on first use and never has to allocate it again, passing in this via the object state.

Customer Impact

Less garbage allocated for the GC to clean up.

Regression

No

Testing

Only what's done by CI.

Risk

Minimal. The change just modifies how this is passed to the callback.

@stephentoub stephentoub requested a review from a team as a code owner June 23, 2021 00:54
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Jun 23, 2021
@ghost ghost requested review from SamBent, fabiant3 and ryalanms June 23, 2021 00:54
@lindexi
Copy link
Member

lindexi commented Jun 23, 2021

Awesome!

@stephentoub stephentoub force-pushed the dispatchertimeralloc branch from 56d9805 to 3686a6a Compare June 23, 2021 01:29
@stephentoub stephentoub force-pushed the dispatchertimeralloc branch from 3686a6a to fdf4efc Compare June 23, 2021 01:37
@ryalanms ryalanms merged commit 03b2ac6 into dotnet:main Aug 17, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants