Skip to content

Faster tool processing - #7

Merged
Deityhub merged 1 commit into
devfrom
fix/performance
Oct 27, 2026
Merged

Deityhub merged 1 commit into
devfrom
fix/performance

Conversation

@Deityhub

Copy link
Copy Markdown
Owner

Tools were slow on big files everywhere (the same timings locally and on Cloudflare): every preview started a new worker and decoded the file again, and our pure-JS codecs and some pixel loops were slow on big photos.

Runs

  • One tool worker is kept warm between runs, and loads the tool's engine when its page opens.
  • Decoded pictures are kept in the worker by input, so changing an option doesn't decode again (up to 512 MB, current inputs only; tools get a copy).

Codecs (appCodec)

  • The browser's native codec for JPEG read and write and opaque PNG write; ours for PNG reading, see-through PNGs (exact), GIF, BMP, and whenever the browser fails.
  • Compress image puts the file's own colour profile and metadata back (the browser's JPEG adds an sRGB profile).
  • Compress PDF reads colour photos through Platform.decodeJpeg and writes them through the codec; grey stays ours. PDF to image writes JPG through the codec.

Engine

  • PNG colour scan skips repeated pixels (PDF to image: 300 pages 14.7 s -> 4.8 s).
  • Blur in row order with integer sums and a quotient table: identical output, about 1.7x faster.
  • No per-pixel allocations in rotate, flip, fill, pixelate, GIF frames; stitch uses overlay (Merge images 0.9 s -> 0.3 s).
  • pngPredictor with one loop per filter type (PNG decode 12 MP 519 -> 351 ms; also PDF streams).

Convert image on a 48 MP photo, changing Save as: 7 to 11 s -> 1.3 to 1.8 s.

Checks

  • typecheck, 831 tests, build.
  • New tests: decode cache, colour profile replacement, pngPredictor against the PNG definition.
  • Outputs checked in the built worker in Chrome: orientation, exact see-through PNG, metadata kept, Compress PDF components, blur, filters, rotate, merge.
  • Only Chrome has been tested.

@github-actions

Copy link
Copy Markdown
Contributor

@Deityhub
Deityhub merged commit 6a01566 into dev Oct 27, 2026
3 checks passed
@Deityhub
Deityhub deleted the fix/performance branch October 27, 2026 21:43
This was referenced Oct 27, 2026
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.

1 participant