Skip to content

fix: move compression and resize to web worker (#41)#42

Merged
leerob merged 6 commits intoleerob:mainfrom
esau-morais:main
Dec 31, 2025
Merged

fix: move compression and resize to web worker (#41)#42
leerob merged 6 commits intoleerob:mainfrom
esau-morais:main

Conversation

@esau-morais
Copy link
Contributor

@esau-morais esau-morais commented Dec 29, 2025

Root Cause: WASM compression was running synchronously on the main thread, blocking the browser UI for several seconds when processing large images (especially at high zoom levels). Chrome shows "unresponsive page" dialog when main thread is blocked for too long.

Fix: Moved compression and resize operations to a Web Worker, allowing:

  1. Main thread to remain responsive during compression
  2. UI updates to happen smoothly
  3. Browser to avoid showing "unresponsive page" warnings

Note

Moves heavy WASM image processing off the main thread and wires the UI to the worker-backed APIs.

  • Add lib/compress.worker.ts to handle compress/resize messages using wasm functions, returning results via postMessage and transferring ArrayBuffers
  • Add lib/compress-client.ts to manage a singleton worker, request/response correlation with timeouts, crash handling, and reconstruction of ImageData; exposes compressImage/resizeImage
  • Update routes/+page.svelte to import from compress-client, route all compression/resize operations through the worker, and simplify the flow (e.g., recompress on resize/apply)
  • Configure Vite (vite.config.ts) with worker.format = "es" for module workers

Written by Cursor Bugbot for commit 0cd81d8. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Dec 29, 2025

@esau-morais is attempting to deploy a commit to the leerob-site Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Dec 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
pixo Ready Ready Preview, Comment Dec 30, 2025 2:32pm

@esau-morais
Copy link
Contributor Author

esau-morais commented Dec 29, 2025

@leerob notice that this fixes the root cause, however does not prevent a long compression time when selecting lossy, as it is already expected and commented in https://github.com/leerob/pixo/blob/main/src/png/mod.rs#L63-L65

EDIT: optimal_compression increases over 20x due to Zopfli

@leerob
Copy link
Owner

leerob commented Dec 29, 2025

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot.

You can kick off a cloud agent using @cursor - e.g. @cursor fix the bug in compress-client.ts.

@leerob leerob merged commit 658975f into leerob:main Dec 31, 2025
6 checks passed
@leerob
Copy link
Owner

leerob commented Dec 31, 2025

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants