Fixing Oversized GIFs for GitHub READMEs, Discord, and Email Newsletters: Real Browser Benchmarks
Screen recordings turned into animated GIFs still show up everywhere: GitHub READMEs, pull request demos, Discord channels, and product update emails. They also fail upload limits constantly. Most guides stop at "run gi
Screen recordings turned into animated GIFs still show up everywhere: GitHub READMEs, pull request demos, Discord channels, and product update emails. They also fail upload limits constantly.
Most guides stop at "run gifsicle -O3 --lossy=80." In practice, that breaks down quickly when you need to hit an exact byte budgetβespecially under 1 MB for email newsletters or 10 MB for GitHub and Discordβand it runs surprisingly slow if you do multi-pass target-size search inside a browser WebAssembly worker.
Here are the real measurements we ran while tuning our client-side Gifsicle WebAssembly pipeline (CompressGIF), including where lossy compression hits a hard floor, when GIF actually beats MP4, and why -O2 cut our multi-pass browser runtime by 37% with zero byte penalty.
1. Platform GIF Budgets You Actually Hit in Production
| Destination | Hard or Practical Limit | What Usually Goes Wrong |
|---|---|---|
| GitHub README / PR comments | 10 MB upload cap | Retina screen recordings at 30β60 fps easily hit 15β40 MB (GitHub GIF preset) |
| Discord (non-Nitro) | 10 MB attachment / 512 KB sticker / 256 KB emoji | High-res gameplay or UI captures exceed 10 MB (Discord GIF preset / 10 MB target) |
| Email newsletters & Gmail | 500 KBβ1 MB practical ceiling | Heavy GIFs stall on mobile data or get clipped in Gmail (Gmail preset / 500 KB target) |
If your source starts as an .mp4 or .mov screen capture, exporting straight to an unconstrained GIF is the easiest way to blow the budget. Keeping frame rate around 10β15 fps and capping width during conversion (e.g. via a video to GIF pass) saves far more bytes than trying to rescue a 60 fps GIF afterward.
2. Why Cranking --lossy=200 Hits a Hard Compression Floor
A common misconception is that turning up lossy compression will keep shrinking a GIF until it meets any target size. It won't.
We tested a real 640Γ360, 40-frame animated GIF (1,141,589 bytes / 1.14 MB) through Gifsicle 1.96 across progressively stricter size targets:
| Step / Strategy | Gifsicle Parameters | Output Size | Reduction | Met Target? |
|---|---|---|---|---|
| Original source (640Γ360, 40 frames) | β | 1,141.6 KB | β | β |
| Target 1 MB | --colors=256 --lossy=20 |
903.3 KB | -20.9% | Yes |
| Target 512 KB | --colors=64 --lossy=165 |
368.7 KB | -67.7% | Yes |
| Target 256 KB (lossy only) | --colors=64 --lossy=200 |
363.5 KB | -68.2% | No (floor hit) |
| Scale width to 512px (80%) | Resize + optimize | 285.1 KB | -75.0% | Close (285 KB) |
| Crop to 420Γ182 + trim to 20 frames |
Crop + trim + --colors=64 --lossy=165
|
201.2 KB | -82.4% | Yes (< 256 KB) |
Look at rows 3 and 4: pushing --lossy from 165 all the way to 200 only shaved 5.2 KB (368.7 KB β 363.5 KB) while visibly degrading frame quality.
Once LZW dictionary compression and palette quantization saturate, the only levers that move the needle are:
- Pixel area (cropping away dead chrome/margins or scaling width down by 20β30%).
- Frame count (trimming idle start/end seconds or dropping duplicate frames).
In our target-size search engine, instead of endlessly retrying higher lossy settings on large inputs, once the best full-dimension candidate is still > 2Γ above the requested byte budget, jumping directly to a scaled resize pass avoids wasted passes and preserves far better visual sharpness than --lossy=200.
3. GIF vs. Animated WebP vs. MP4: Not Always a Clean Sweep
Before forcing everything into GIF, check whether the host supports <video> (MP4) or animated WebPβand know the one case where GIF actually wins.
Here are measurements on three distinct clips:
| Clip Type | Source GIF | Optimized GIF | Animated WebP | MP4 (H.264) |
|---|---|---|---|---|
| Complex 640Γ360 (40 frames) | 1,141.6 KB | 903.3 KB | 468.5 KB | 91.5 KB |
| Smooth color gradient | 393.5 KB | 377.2 KB | 202.2 KB | 14.5 KB |
| Flat UI micro-interaction | 5.9 KB | 4.7 KB | 3.3 KB | 10.8 KB |
Two takeaways stand out:
- For complex motion and gradients, MP4 is 10Γβ25Γ smaller than GIF, and animated WebP is roughly half the size of GIF. (Conversely, if you inherit an animated
.webpthat a legacy CMS or email client rejects, converting WebP to GIF works best when paired with palette tuning.) - For tiny flat-UI clips (5β15 KB icons, button state demos), MP4 container metadata overhead makes the file larger than an optimized GIF (
10.8 KBvs4.7 KB).
4. Browser WebAssembly Speed: --optimize=2 vs. --optimize=3
When running gifsicle inside a browser Web Worker via WebAssembly to binary-search for a target file size (say, hitting under 500 KB or 10 MB without uploading user files to a server), every candidate pass multiplies total wall-clock latency.
We benchmarked gifsicle 1.96 compiled to .wasm on the same 1.14 MB 40-frame GIF across all 8 candidate lossy passes:
| Optimization Flag | Total Time (8 Passes) | Output Sizes Across All 8 Passes (KB) |
|---|---|---|
--optimize=3 |
2,290 ms | 1084 / 903 / 817 / 601 / 577 / 563 / 369 / 363 |
--optimize=2 |
1,447 ms (-37%) | 1084 / 903 / 817 / 601 / 577 / 563 / 369 / 363 |
On multi-megabyte screen recordings (5β20 MB), --optimize=3's exhaustive inter-frame transparency search scales super-linearly and can stall browser tabs for 30β60+ secondsβcausing users to switch tabs or abandon the page.
Two practical changes made a big difference in browser WebAssembly execution:
-
Use
--optimize=2for browser inputs >= 1 MB while keeping--optimize=3for small files where exhaustive transparency search is sub-second. -
Cache the compiled
WebAssembly.Moduleper Worker viaWebAssembly.compileStreaming()and pass it into Emscripten'sinstantiateWasmhook so each candidate pass instantiates cleanly without re-fetching or recompiling the.wasmbinary:
let compiledWasmPromise = null;
async function getCompiledWasm(wasmUrl) {
if (!compiledWasmPromise) {
compiledWasmPromise = WebAssembly.compileStreaming(fetch(wasmUrl))
.catch(async () => {
const res = await fetch(wasmUrl);
return WebAssembly.compile(await res.arrayBuffer());
});
}
return compiledWasmPromise;
}
Takeaways
- Don't fight the GIF lossy floor: if
--lossy=140β165still misses your target, crop margins, drop frames, or scale down 20% instead of pushing--lossy=200. - Use MP4 or WebP when the platform allows it, except for tiny flat-UI clips where GIF/WebP avoid MP4 container overhead.
- If you run
gifsiclein browser WebAssembly across multiple passes, cachingWebAssembly.Moduleand switching >= 1 MB inputs from-O3to-O2cuts execution time by ~37β47% with virtually identical file sizes.
Disclosure: I maintain CompressGIF, a browser-based GIF compressor and converter powered by Gifsicle and FFmpeg WebAssembly, where these benchmarks were measured.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.