Skip to content

Optimize LoomManager async scheduling path - #7

Merged
Eerrly merged 1 commit into
mainfrom
codex/find-optimization-opportunities-without-structural-changes
Apr 13, 2026
Merged

Optimize LoomManager async scheduling path#7
Eerrly merged 1 commit into
mainfrom
codex/find-optimization-opportunities-without-structural-changes

Conversation

@Eerrly

@Eerrly Eerrly commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Reduce allocations and improve stability in LoomManager's async scheduling and delayed-invocation loops while keeping the overall structure unchanged.
  • Avoid potential race conditions when producers enqueue async actions while the main thread consumes them.

Description

  • Introduce named constants ThreadPoolMaxWorkerThreads and ThreadPoolMinWorkerThreads and use them in Initialize to replace magic numbers.
  • Cache a WaitCallback in the readonly field _runActionCallback (assigned in the new constructor) and use it instead of allocating new WaitCallback(RunAction) on each dispatch.
  • Add locking around _waitingAsyncActions for safe enqueue/dequeue and change Update to dequeue a single waiting action under lock then schedule it, preventing double-dequeue and races.
  • Cache Time.unscaledTime and Time.frameCount at the start of Update and use the cached values inside the delay loops to reduce repeated Unity API calls.

Testing

  • No automated Unity build or runtime tests were executed in this environment.
  • The patch was applied and the modified file was inspected and verified for expected diffs and basic consistency within the repository environment.

Codex Task

@Eerrly
Eerrly merged commit ad8e83d into main Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant