Skip to content

reduce overhead when running in no main thread mode#1502

Merged
lifengl merged 3 commits into
mainfrom
dev/lifengl/reduceOverheadNoMainThreadMode
Nov 11, 2025
Merged

reduce overhead when running in no main thread mode#1502
lifengl merged 3 commits into
mainfrom
dev/lifengl/reduceOverheadNoMainThreadMode

Conversation

@lifengl

@lifengl lifengl commented Nov 5, 2025

Copy link
Copy Markdown
Member

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.

Lifeng Lu 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.
@lifengl lifengl changed the title reduce overhead no main thread mode reduce overhead when running in no main thread mode Nov 5, 2025
@lifengl lifengl merged commit 45dad1e into main Nov 11, 2025
8 of 9 checks passed
@lifengl lifengl deleted the dev/lifengl/reduceOverheadNoMainThreadMode branch November 11, 2025 20:06
This was referenced Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants