From c0c03d02b0778216e49d31d92bbdce11da140ac4 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 4 Dec 2023 21:46:20 -0500 Subject: [PATCH] Add microtasks to render loop to lessen thread-blocking --- lib/backend.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/backend.ts b/lib/backend.ts index e924ce0..91e3687 100644 --- a/lib/backend.ts +++ b/lib/backend.ts @@ -277,6 +277,7 @@ async function render(bbox: BBOX, options: Options = {}) { for (const feature of features) { drawn++; progress(`Drawing (${drawn} / ${features.length} elements)`); + await new Promise((resolve) => resolve()); const name = feature.properties?.name; switch (feature.geometry.type) { @@ -438,6 +439,7 @@ async function render(bbox: BBOX, options: Options = {}) { const features = grouped.get(group); if (!features) continue; for (let feature of features) { + await new Promise((resolve) => resolve()); const name = feature.properties?.name; if (!(feature.geometry.type === "LineString" && name)) continue; if (labeledNames.has(name) || name.length > MAX_NAME_LENGTH) continue;