From 90e17dee9632cecf22608daa82c93cc0f9d0c5c4 Mon Sep 17 00:00:00 2001
From: memdmp <memdmp@estrogen.zone>
Date: Mon, 30 Mar 2026 19:38:33 +0200
Subject: fix: use toBlob to significantly improve performance toObjectURL used
 to use 70-ish % of the render time, toBlob only uses 13%

---
 src/lib/Renderer/Renderer.svelte | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'src/lib/Renderer/Renderer.svelte')

diff --git a/src/lib/Renderer/Renderer.svelte b/src/lib/Renderer/Renderer.svelte
index e848312..c3223a6 100644
--- a/src/lib/Renderer/Renderer.svelte
+++ b/src/lib/Renderer/Renderer.svelte
@@ -58,7 +58,12 @@
 				seconds: frame / video.fps
 			});
 			// TODO: see if we can pipe this into an active ffmpeg instead of writing a file then running a command after
-			const file = await fetchFile(c.toDataURL());
+			const blob = await new Promise<Blob>((rs, rj) =>
+				c.toBlob((blob) => (blob ? rs(blob) : rj(new Error('No blob gotten back'))), 'image/png')
+			);
+			const u = URL.createObjectURL(blob);
+			const file = await fetchFile(u);
+			URL.revokeObjectURL(u);
 			await ffmpeg.writeFile('frames/f' + frame.toString().padStart(10, '0') + '.png', file);
 			if (performance.now() > lastAnimationFrame + 33) {
 				await new Promise((rs) => requestAnimationFrame(rs));
-- 
cgit v1.2.3

