-
Notifications
You must be signed in to change notification settings - Fork 80
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
Use microtask queue to flush autoruns... #306
Conversation
63ecfbf
to
9e04bb8
Compare
With the last commit (using |
9e04bb8
to
c7885f2
Compare
seems good, this may need to be major bump, so it can ride the canary train in ember. Some caveats may exist re: popup blockers and window.open being run in autoruns. Table of funky behavior is here: #181 (we may deem it irrelevant) |
Ya, we definitely want it to go through a full canary -> beta -> release cycle so we can ensure this has no negative ramifications. FWIW, I have been working on the next step (advancing from queue to queue during an autorun via microtask queue flushes) in rwjblue#1 if you are interested in the followup progress... |
Sounds like a good approach. My long-term thought was to essentially make auto-run default, and if |
Yep, that’s exactly the direction I am pushing on. Will pester you tomorrow to chat through it some more 😆... |
lib/index.ts
Outdated
platform.clearNext = _platform.clearNext || platform.clearTimeout; | ||
platform.now = _platform.now || (() => Date.now()); | ||
|
||
this._platform = platform; | ||
// TODO: do we need this? | ||
if (_platform.next) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make this configurable, and just plug in RSVP's asap in ember? Then we avoid duplicate code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make asap also use native Promise for its asap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stefanpenner - I think we want to avoid the extra level of queuing that RSVP.asap
does. Specifically we need to leverage the fact that microtasks that we enqueue are in the correct position (e.g. interleaving of native promises and RSVP.Promise
s should maintain the same resolve ordering).
e3286b5
to
33755a5
Compare
33755a5
to
c2965dc
Compare
lib/backburner/host-platform.ts
Outdated
@@ -0,0 +1,53 @@ | |||
export interface IPlatform { | |||
setTimeout(fn: () => void, ms: number): any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn: Function
lib/backburner/host-platform.ts
Outdated
const SET_TIMEOUT = setTimeout; | ||
const NOOP = () => {}; | ||
|
||
export function buildDefaultPlatform(flush: () => void): IPlatform { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we just configure asap
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m concerned with swapping to asap as it adds another layer of queuing and the exact ordering of interleaved RSVP promises, native promises, and BB queue transitions are super important...
However, this “host” interface style was explicitly designed to allow Ember to use RSVP.asap if it wants (it only needs to pass a _buildPlatform
function that uses RSVP.asap
for the provided next
(you can see some examples in the tests)...
lib/index.ts
Outdated
@@ -137,7 +151,7 @@ export default class Backburner { | |||
return current; | |||
} | |||
|
|||
public end() { | |||
public end(fromAutorun = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to not expose this flag via a public API, we should maybe create _end
that can have w/e flag, but if at all possible keep the existing one pristine (if possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, totally makes sense.
84a04d7
to
984ebcd
Compare
984ebcd
to
0fa00ae
Compare
* Replace the private `_platform` option, with a new `_buildPlatform` * Add interfaces for the constructor args for the `Backburner` class. * Move the main implementation of `Backburner.prototype.end` into a private method (`_end`) that is aware of if the end is from an autorun or manual run... * Extract steps to schedule an autorun out into stand alone private method (`_scheduleAutorun`) * Leverage microtask queue (via either `promise.then(...)` or `MutationObserver`) to schedule an autorun * Leverage microtask queue to advance from one queue to the next
0fa00ae
to
27690de
Compare
I just ran a series of benchmarks comparing various versions of backburner (v0.3.1 used by Ember 2.13, v1.3.4 used by Ember 2.18, v2.1.0 used by Ember 3.0.0-beta.5, master at e65437d, and this PR's changes) against a complex real world app. As you can see below, compared to e65437d we have a very high confidence that this has a positive impact on performance (estimated difference is |
@stefanpenner / @krisselden - I'd like to land this (given the strong evidence shown above) so that we can update Ember and continue fleshing out our plans RE: native promises and whatnot. Any objections? |
Addressed and replied inline...
_platform
option, with a new_buildPlatform
Backburner
class.Backburner.prototype.end
into aprivate method (
_end
) that is aware of if the end is from an autorunor manual run...
method (
_scheduleAutorun
)promise.then(...)
orMutationObserver
) to schedule an autorunThis PR is just a small stepping stone towards leveraging microtasks a bit more (with the goal of removing Ember's autorun assertion)...