Re:Main-Thread-Scheduling
by astoilkov on Friday January 05, 2024 @09:57AM
(#38879696)
The author here. Just opened HN and saw that my library is on the front page . If you have any questions, I can answer them.
[ Parent
| on HN ]
How does this differ from cooperative multi tasking?
If I'm reading this correctly, this is a library for use within a browser, in which case the answer is that this makes it easier to live within the constraints of the browser, which has arguably the strangest "multitasking" support anywhere, what with all the constraints it had to satisfy to be added in to an architecture already 15 years old at that point.
Yeah, that sums it up. The library tries to use the single thread the browser UI is running on and just not freeze it.
Have you benchmarked the overhead of awaiting? I believe that in doing so you yield to the microtask queue and then your function has to be scheduled and run again. You could compare
await yieldOrContinue('user-visible');
doSomeWork();
against if (isTimeToYield('user-visible')) {
await yieldControl('user-visible');
}
doSomeWork();
A few years back when I measured it on a fast laptop the cost was ~1µs to do `await 0;`I haven't. I should do that. Many people are talking about this and this makes me think I should measure and talk about it in the readme. Thanks!
Hi, forgive me if I missed it, I just briefly browsed the repo. Does the library itself handle cancellation, or would user code be responsible for that?