wrapPerformWorkWithCoroutine unnessarially creates a thread each time its called

Open
#9 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
lua
Domain
performance

Research direction

Start in modules/scheduler/src/forks/SchedulerHostConfig.default.lua at wrapPerformWorkWithCoroutine() and performWorkUntilDeadline(). Measure the current thread creation and inspect how coroutine.yield(), xpcall, error handling, and yielding scheduledHostCallback interact. Done means avoiding unnecessary thread creation while preserving error handling and scheduler behavior.

Written by the indexing model from the issue text.

Description

Currently in the default host config for the scheduler, a new thread is made each time wrapPerformWorkWithCoroutine() is called.
When this is unnecessary given performWorkUntilDeadline() already uses xpcall and handles errors (not if ReactGlobals.__YOLO__ is disabled but that can be changed), and an inlined version could be used in wrapPerformWorkWithCoroutine() with coroutine.yield() replacing the use of error(), or alternatively dependency injection could be used for providing a function to be used like how error() is currently in performWorkUntilDeadline().

Thread Pooling would also then be used for wrapPerformWorkWithCoroutine() as to handle the cases where the scheduledHostCallback yields (fairly certain it can?).

I haven't tested the performance impact this makes, but I would expect it to not be insignificant given threads are one of the most heavy things memory wise and for the GC. Especially as the function returned by wrapPerformWorkWithCoroutine is called frequently as its part of the scheduler.
Edit: Will be testing eventually when I get the time

Dominant language
Luau
Stars
568
Forks
49
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Roblox/react-luau

All issues in Roblox/react-luau

Similar issues

More Performance issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.