JavaScriptKit icon indicating copy to clipboard operation
JavaScriptKit copied to clipboard

Event loop scheduling improvement

Open kateinoigakukun opened this issue 1 year ago • 0 comments

Motivation

Think the following situation:

  1. The browser event loop has a pending event that fires an event listener that schedules high-priority work to JSKit's executor.
  2. But the current JSKit's executor loop does not yield its control to JS event loop until all enqueued works are done
  • Even if some of them are low-priority

It resulted in the higher priority works planned to be enqueued to JSKit's executor are blocked by lower priority works that are already enqueued even though browser engine knows about the pending event.

Outcome

  • Performance gain

Potential solution

Although yielding control to JS engine for every Swift job is not a realistic approach due to high overheads, but it's still considerable to yield control when certain time is spent for the current JSKit's executor loop.

kateinoigakukun avatar Feb 07 '25 06:02 kateinoigakukun