reduce overhead when running in no main thread mode#1502
Merged
Conversation
added 3 commits
November 5, 2025 13:41
Generally, post to context would not be used as SwitchToMainThread is no-op in this context. Even it is being called under certain corner cases, it would just queue the same work item to the thread pool multiple times, so better to prevent the allocation in the first place.
…s used in no main thread mode. Because IsOnMainThread is just to check the thread id, this can be turned on randomly when the code is running in the initial thread pool thread. It would turn on expensive dependency tracking graph, which is not what we expect to do.
…main thread mode.
AArnott
approved these changes
Nov 8, 2025
This was referenced Jun 22, 2026
Open
Open
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The primary reason is IsOnMainThread only check the thread id matches the initial thread id, so it can be true if the task happens to start on the same thread pool thread to initialize the JoinableTaskContext in a no main thread application. It leads some unnecessary work, including marking the task main thread blocking, and tracking its dependent tasks.
All these work, including tracking nested factories seem to be unnecessary in this mode.