From ece847ef5052184e65e6a483a522f86f9f6c0010 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 4 Sep 2026 07:19:32 +0000 Subject: [PATCH] Optimize HTML5 file drop to parse files in parallel Replaced the sequential `for...of` loop with `Promise.all` for reading dropped files via the HTML5 File API. Previously, when multiple files were dropped, the application awaited each file's `text()` promise sequentially, causing unnecessary delays. Parallelizing this provides a significant speedup for large batches of files. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src/storage.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/storage.ts b/src/storage.ts index 211180b..9f19d11 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -324,8 +324,11 @@ export async function onFileDrop(cb: (content: string) => void): Promise { window.addEventListener("dragover", (e) => e.preventDefault()); window.addEventListener("drop", async (e) => { e.preventDefault(); - for (const f of e.dataTransfer?.files ?? []) { - if (/\.(numi|txt|md)$/i.test(f.name)) cb(await f.text()); - } + const files = Array.from(e.dataTransfer?.files ?? []); + await Promise.all( + files + .filter((f) => /\.(numi|txt|md)$/i.test(f.name)) + .map(async (f) => cb(await f.text())) + ); }); }