perf(web): skip base64 for oversized image candidates - #5220
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved 2a67bcf This is a straightforward performance optimization that adds early-exit logic to avoid expensive base64 encoding when the output would clearly exceed the budget. The caller already handles null returns correctly, and user-facing behavior is unchanged. You can customize Macroscope's approvability policy. Learn more. |
What Changed
Why
Image compression previously converted every canvas candidate to base64 before checking whether it fit. Large images repeated this work across each quality and downscale attempt.
In CI, the existing 12-test image compression suite dropped from 28.99 seconds and a timeout to 5.48 seconds. A focused local run completed in 1.19 seconds.
Checklist
Model: GPT-5.6; harness: T3 Code.
Note
Low Risk
Localized performance change in image encoding with the same budget checks; no auth, security, or API surface changes.
Overview
Image compression no longer converts every encode attempt to a base64 data URL before checking the stash/send size budget.
encodeCanvas(renamed fromencodeToDataUrl) takes a character budget and rejects oversized results early:toDataURLpaths compare string length, and OffscreenCanvas paths estimate base64 length from the blob size before callingblobToDataUrl. The quality ladder inencodeWithinBudgetonly returns encodings that fit the budget instead of keeping the smallest over-budget candidate from each step.This cuts redundant base64 work across quality and downscale retries, which drove a large drop in CI time for the image compression test suite.
Reviewed by Cursor Bugbot for commit 2a67bcf. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Skip base64 encoding for oversized image candidates in
encodeWithinBudgetencodeCanvasin imageCompression.ts now accepts abudgetCharsparameter and returnsnullfordataUrlwhen the encoded size exceeds the budget, avoiding unnecessary base64 conversion for large blobs.encodeWithinBudgetnow returnsnullwhen no encoding fits within the budget, rather than falling back to the smallest over-budget encoding.nullwhen no candidate fits.Macroscope summarized 2a67bcf.