From 45053c26e35b5def5a372f6fb16610962340da7c Mon Sep 17 00:00:00 2001 From: Jordan Gensler Date: Mon, 3 Feb 2020 13:41:57 -0800 Subject: [PATCH] Avoid using shift in flush We noticed that there was a large amount of memory being created as part of the flush method, which seems to be due to some array optimizations in old JS engines. This seems to be easily fixed by changing to a simple for loop instead of a while loop that modifies the array during iteration. This is the same pattern that is used for the `render_callbacks`. --- src/runtime/internal/scheduler.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/internal/scheduler.ts b/src/runtime/internal/scheduler.ts index 1ce255b217..96fecc1fec 100644 --- a/src/runtime/internal/scheduler.ts +++ b/src/runtime/internal/scheduler.ts @@ -37,11 +37,13 @@ export function flush() { do { // first, call beforeUpdate functions // and update components - while (dirty_components.length) { - const component = dirty_components.shift(); + for (let i = 0; i < dirty_components.length; i += 1) { + const component = dirty_components[i]; set_current_component(component); update(component.$$); } + + dirty_components.length = 0; while (binding_callbacks.length) binding_callbacks.pop()();