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

perf: Reuse the same promise instance in the scheduler #2555

Merged
merged 1 commit into from
Apr 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/internal/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import { set_current_component } from './lifecycle.js';
export const dirty_components = [];
export const intros = { enabled: false };

let update_promise;
const resolved_promise = Promise.resolve();
let update_scheduled = false;
const binding_callbacks = [];
const render_callbacks = [];
const flush_callbacks = [];

export function schedule_update() {
if (!update_promise) {
update_promise = Promise.resolve();
update_promise.then(flush);
if (!update_scheduled) {
update_scheduled = true;
resolved_promise.then(flush);
}
}

export function tick() {
schedule_update();
return update_promise;
return resolved_promise;
}

export function add_binding_callback(fn) {
Expand Down Expand Up @@ -65,7 +66,7 @@ export function flush() {
flush_callbacks.pop()();
}

update_promise = null;
update_scheduled = false;
}

function update($$) {
Expand All @@ -77,4 +78,4 @@ function update($$) {

$$.after_render.forEach(add_render_callback);
}
}
}