Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fix access to Task.Id while finishing continuations #3139

Merged
merged 1 commit into from
Feb 11, 2016

Conversation

stephentoub
Copy link
Member

Task.Id is lazily-initialized with an interlocked operation and we strive to avoid accessing it anywhere in Task's internals on hot paths, but apparently when some ETW logging was added around continuations, calls were added that access Task.Id even if logging is disabled. This is accounting for ~30% of the cycles consumed in a TCS Task's lifecycle! This commit fixes it by making sure these accesses to Id are guarded.

cc: @AlfredoMS

Task.Id is lazily-initialized with an interlocked operation and we strive to avoid accessing it anywhere in Task's internals on hot paths, but apparently when some ETW logging was added around continuations, calls were added that access Task.Id even if logging is disabled.  This is accounting for ~30% of the cycles consumed in a TCS Task's lifecycle!  This commit fixes it by making sure these accesses to Id are guarded.
@AlfredoMS
Copy link

LGTM, this is makes it consistent with all other calls to the TplEtw Logger

stephentoub added a commit that referenced this pull request Feb 11, 2016
Fix access to Task.Id while finishing continuations
@stephentoub stephentoub merged commit 6ac7e96 into dotnet:master Feb 11, 2016
@stephentoub stephentoub deleted the task_id_perf branch February 11, 2016 23:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants