Skip to content

gamut-png: race an equal-raw-size chunk-free candidate instead of declining it #514

Description

@justin13888

Summary

reduce::analyze8 selects the chunk-free runner-up handed to PngEncoder::write_reduced_or_native under a strict saving rule: a candidate whose raw size merely equals the incumbent's is declined rather than entered into the race.

Raised as design question 3 in the re-review of PR #485 and recorded there as kept-for-now, with the argument accepted as sound.

The argument

Declining an equal-raw-size candidate repeats, one level down, the error PR #485 exists to remove: a raw estimate cannot see DEFLATE. Two candidates of equal raw size can compress differently once the colour type changes, because the colour type changes which filters apply and what the per-scanline residuals look like — the same reason the palette-vs-native decision was converted from a raw-size estimate into a real race (STATUS.md, "The cost model, and why it is a race").

So an equal-raw-size chunk-free candidate is not known to be equivalent to the incumbent; it is only known to be the same size before compression, which is precisely the quantity that was shown not to predict the finished file.

Site

reduce::analyze8's strict < runner-up rule (the chunk-free candidate selection feeding Reductions). The change would be <<=, entering the tied candidate into the existing three-way race, where prefers_chunk_free's documented tie-break already decides the outcome deterministically if the finished files also tie.

Why it was not changed in #485

It is a heuristic change, and this repository's rule is that a win nobody measured is not a reason (AGENTS.md). It needs measurement, not argument.

Acceptance measure

  • the tests/size_contract.rs corpus — no row may regress, and the change is worth taking only if some row improves;
  • the per-candidate encode cost: relaxing the rule admits more candidates to the race, and the worst case is already 42 filter-plus-DEFLATE passes for one file (STATUS.md). A row that gains nothing but costs an extra full encode is a loss.

Both are already produced by cargo bench -p gamut-png and gated by tests/size_contract.rs, so the experiment is a measurement against an existing harness rather than new tooling.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions