Skip to content

feat: add a budget mode that compares quality at equal file size - #63

Merged
nucliweb merged 1 commit into
mainfrom
feat/target-bytes
Nov 27, 2026
Merged

nucliweb merged 1 commit into
mainfrom
feat/target-bytes

Conversation

@nucliweb

Copy link
Copy Markdown
Owner

Summary

Adds --target-bytes <size> to compare-codecs: the inverse of the equal-quality search. Given a byte budget, each codec is searched for the largest file that fits, and codecs are ranked by the ssimulacra2 they reach at that size, the question a web performance budget asks.

  • Units are explicit: KB/MB are decimal, KiB/MiB binary, a bare number is bytes. Tables state the budget both ways and show exact byte sizes plus the share of the budget used.
  • A file over the budget is never chosen while one under it exists. A codec that cannot fit even at its lowest quality is flagged * and ranked after the rest.
  • The search only reads the encoded size, so it decodes and scores once per codec: on the seven demo images a 30 KB run takes 29 s against 63 s for an equal-quality run.
  • The batch summary averages quality, and the difference from mozjpeg, over the images where every codec fits, so codecs are ranked on the same images; wins and fit counts cover every image.
  • --csv writes one row per image and codec with budget_bytes and fits. --html, --rd and --target are rejected alongside it; budget mode in the HTML report stays on the roadmap.

The quality and budget searches share the encode step, timing totals and final measurement in pipeline.js, and the CLI's three modes share one image-normalization helper.

Testing

  • 29 new tests: byte-size parsing, the budget search, table/CSV/summary rendering, gated integration tests on real encoders, and CLI tests (including rejected flag combinations, which run without codecs).
  • node --test: 128 pass locally (2 codec-gated skips), 130/130 inside ghcr.io/nucliweb/image-tools:latest.
  • End-to-end runs on the seven demo images with all six codecs, locally and in the Docker image.

--target-bytes searches each codec for the largest file that fits a byte budget (KB/MB decimal, KiB/MiB binary, or a bare byte count) and ranks codecs by the ssimulacra2 they reach there. The search reads only the encoded size, so it decodes and scores once per codec, which makes a budget run about half as long as an equal-quality run on the demo images.

The batch summary averages quality over the images where every codec fits, so codecs are ranked on the same images. Tables, summary and CSV are supported; --html, --rd and --target are rejected alongside it.
@github-actions

Copy link
Copy Markdown

Codec comparison ✅ no size or quality regression

📥 Download the codec report (unzip and open report.html locally). Available until 2027-02-25, when GitHub deletes the artifact.

Size check
Size regression check (target 90, size tolerance 2.0%, quality tolerance 0.5 ssimulacra2)

  ok         cid22-blossoms.png  JPEG XL  base 105038 → 105038  (+0.00%)  ss2 90.08 → 90.09  (+0.02)
  ok         cid22-blossoms.png  WebP  base 118162 → 118162  (+0.00%)  ss2 76.87 → 76.87  (+0.00)
  ok         cid22-blossoms.png  AVIF  base 128030 → 128030  (+0.00%)  ss2 89.75 → 89.75  (+0.00)
  ok         cid22-blossoms.png  jpegli  base 137045 → 137045  (+0.00%)  ss2 90.11 → 90.11  (+0.00)
  ok         cid22-blossoms.png  mozjpeg  base 164234 → 164234  (+0.00%)  ss2 90.20 → 90.20  (+0.00)
  ok         cid22-blossoms.png  HEIC  base 194761 → 194761  (+0.00%)  ss2 82.22 → 82.22  (+0.00)
  ok         cid22-church.png  JPEG XL  base 61171 → 61171  (+0.00%)  ss2 89.85 → 89.83  (-0.03)
  ok         cid22-church.png  AVIF  base 68127 → 68127  (+0.00%)  ss2 89.73 → 89.73  (+0.00)
  ok         cid22-church.png  HEIC  base 71021 → 71021  (+0.00%)  ss2 90.11 → 90.11  (+0.00)
  ok         cid22-church.png  jpegli  base 78183 → 78183  (+0.00%)  ss2 89.74 → 89.74  (+0.00)
  ok         cid22-church.png  WebP  base 94246 → 94246  (+0.00%)  ss2 88.91 → 88.91  (+0.00)
  ok         cid22-church.png  mozjpeg  base 99280 → 99280  (+0.00%)  ss2 89.89 → 89.89  (+0.00)
  ok         cid22-friends.png  JPEG XL  base 52793 → 52793  (+0.00%)  ss2 89.83 → 89.85  (+0.02)
  ok         cid22-friends.png  AVIF  base 54356 → 54356  (+0.00%)  ss2 89.97 → 89.97  (+0.00)
  ok         cid22-friends.png  jpegli  base 64424 → 64424  (+0.00%)  ss2 89.80 → 89.80  (+0.00)
  ok         cid22-friends.png  HEIC  base 79196 → 79196  (+0.00%)  ss2 90.01 → 90.01  (+0.00)
  ok         cid22-friends.png  WebP  base 87218 → 87218  (+0.00%)  ss2 89.44 → 89.44  (+0.00)
  ok         cid22-friends.png  mozjpeg  base 91561 → 91561  (+0.00%)  ss2 90.25 → 90.25  (+0.00)
  ok         corporate-memphis.png  AVIF  base 19074 → 19074  (+0.00%)  ss2 89.87 → 89.87  (+0.00)
  ok         corporate-memphis.png  JPEG XL  base 44539 → 44539  (+0.00%)  ss2 90.24 → 90.22  (-0.02)
  ok         corporate-memphis.png  WebP  base 46758 → 46758  (+0.00%)  ss2 85.87 → 85.87  (+0.00)
  ok         corporate-memphis.png  HEIC  base 68663 → 68663  (+0.00%)  ss2 88.01 → 88.01  (+0.00)
  ok         corporate-memphis.png  jpegli  base 80411 → 80411  (+0.00%)  ss2 89.92 → 89.92  (+0.00)
  ok         corporate-memphis.png  mozjpeg  base 100129 → 100129  (+0.00%)  ss2 89.62 → 89.62  (+0.00)
  ok         forest-leaves.png  JPEG XL  base 626391 → 626391  (+0.00%)  ss2 89.67 → 89.68  (+0.01)
  ok         forest-leaves.png  HEIC  base 678675 → 678675  (+0.00%)  ss2 89.87 → 89.87  (+0.00)
  ok         forest-leaves.png  jpegli  base 741875 → 741875  (+0.00%)  ss2 89.87 → 89.87  (+0.00)
  ok         forest-leaves.png  WebP  base 753448 → 753448  (+0.00%)  ss2 89.52 → 89.52  (+0.00)
  ok         forest-leaves.png  AVIF  base 824552 → 824552  (+0.00%)  ss2 90.45 → 90.45  (+0.00)
  ok         forest-leaves.png  mozjpeg  base 1119980 → 1119980  (+0.00%)  ss2 89.60 → 89.60  (+0.00)
  ok         pipeline-diagram.png  AVIF  base 62798 → 62798  (+0.00%)  ss2 90.07 → 90.07  (+0.00)
  ok         pipeline-diagram.png  WebP  base 63042 → 63042  (+0.00%)  ss2 73.46 → 73.46  (+0.00)
  ok         pipeline-diagram.png  JPEG XL  base 75252 → 75252  (+0.00%)  ss2 89.83 → 89.80  (-0.02)
  ok         pipeline-diagram.png  HEIC  base 97122 → 97122  (+0.00%)  ss2 73.38 → 73.38  (+0.00)
  ok         pipeline-diagram.png  jpegli  base 113660 → 113660  (+0.00%)  ss2 89.27 → 89.27  (+0.00)
  ok         pipeline-diagram.png  mozjpeg  base 180740 → 180740  (+0.00%)  ss2 89.86 → 89.86  (+0.00)
  ok         report-ui.png  AVIF  base 64121 → 64121  (+0.00%)  ss2 89.82 → 89.82  (+0.00)
  ok         report-ui.png  JPEG XL  base 98049 → 98049  (+0.00%)  ss2 89.61 → 89.59  (-0.02)
  ok         report-ui.png  WebP  base 117598 → 117598  (+0.00%)  ss2 77.40 → 77.40  (+0.00)
  ok         report-ui.png  jpegli  base 169432 → 169432  (+0.00%)  ss2 89.92 → 89.92  (+0.00)
  ok         report-ui.png  HEIC  base 174308 → 174308  (+0.00%)  ss2 83.19 → 83.19  (+0.00)
  ok         report-ui.png  mozjpeg  base 218438 → 218438  (+0.00%)  ss2 90.25 → 90.25  (+0.00)

OK: no size or quality regressions.

@nucliweb
nucliweb merged commit fcca75e into main Nov 27, 2026
2 checks passed
@nucliweb
nucliweb deleted the feat/target-bytes branch November 27, 2026 08:03
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