Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should post a task instead of using idle callbacks #149

Closed
esprehn opened this issue Aug 15, 2016 · 2 comments
Closed

Should post a task instead of using idle callbacks #149

esprehn opened this issue Aug 15, 2016 · 2 comments

Comments

@esprehn
Copy link
Collaborator

esprehn commented Aug 15, 2016

Idle callbacks brings a bunch of baggage:

  • Idle callbacks means on busy machines (or situations where the scheduler thinks the work is not a priority) that the callback is delayed 100ms.
  • The 100ms delay is specifically targeting a specific ads standard, but this API is more general than that. Different timeouts make sense for different use cases.
  • Having to use takeRecords + a scroll listener means you're listening for every scroll even when it's not needed which breaks one of the big use cases which was not avoid scroll listeners.
  • Calling requestIdleCallback from inside an IO callback always pushes you a frame forward because of the semantics of rIc.
  • Only Chrome supports idle callbacks so far and the scheduler work to have them is non-trivial. Coupling a super useful feature like IO to it is unfortunate for other implementations.

We've also never forced this kind of scheduling with timeouts on the platform before. I don't think we understand the ecosystem implications properly, and some authors are already not happy with it.

We'd be better of removing this from the spec and instead letting developers compose the primitives themselves (rIc, IO, setTimeout, etc.).

Long term we can consider sugar to make idle callbacks nicer in a general purpose scheduling API, for example:

Scheduler.atIdle(Function, opts) => Function
Scheduler.atTimeout(Function, opts) => Function
Scheduler.atMicrotask(Function, opts) => Function

etc. which allows you to easily vend a function that defers the execution to a different point in time, then you can do:

var observer = new IntersectionObserver(Scheduler.atIdle((records) => {
  // ...
}, {timeout: 100}));
@ziyunfei
Copy link

@ojanvafai
Copy link
Collaborator

I'll try to update the spec shortly. Didn't seem urgent since no other
browser implements idle callbacks.

On Sat, Sep 10, 2016, 1:43 AM ziyunfei notifications@github.com wrote:

http://crrev.com/31768c865c398d024d8adad8cd5d9f2b182d12c2


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#149 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABiGA9f6_a6xnWeGpNgN6l7WIZktnwCbks5qom2ggaJpZM4JkswE
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants