google / google/brotli

quality=11 output is larger than quality=1 output for the same input

Open
#1,485 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
14.9k
Forks
1.4k
Avg merge
4d 20h
Merged PRs (30d)
9

Description

## Summary

With a specific input, one-shot Brotli compression with `BrotliEncoderCompress()` produces a larger output at `quality=11` than at `quality=1` when the same mode and window settings are used.

The attached reproducer reads the input once, compresses it with `quality=1`, compresses the same bytes with `quality=11`, and prints the compressed sizes.
In the observed result, the `quality=1` output is 164 bytes and the `quality=11` output is 165 bytes.

If higher quality is expected to optimize compression density monotonically for the same input and encoder settings, the `quality=11` output is expected to be smaller than or equal to the `quality=1` output. If size monotonicity across quality levels is not guaranteed, this behavior may need clarification in the encoder documentation.

## Environment

The observation below was collected on:

```text
OS: Ubuntu 20.04.6 LTS (Focal Fossa), x86_64
Compiler for the standalone reproducer: gcc 9.4.0
Brotli source version: 1.2.0
Git commit: ab685df8343d8046226ece980408e958c10f9085
```

## Observation

### Running on Brotli encoder version 0x01000007

Running the attached reproducer and input produces:

```text
Brotli encoder version: 0x01000007
input size: 161
quality 1 compressed size: 164
quality 11 compressed size: 165
quality 11 output is larger than quality 1 output
```

The reproducer therefore observes a one-byte size increase when moving from `quality=1` to `quality=11` for the same input.

## Reproduce steps

The attachments are:

```text
brotli_quality_size_repro.c
brotli_quality_test_input.bin
```

Compile the reproducer against the Brotli encoder library:

```sh
cc -O0 -g brotli_quality_size_repro.c -lbrotlienc -o repro
```

Run it with the attached input:

```sh
./repro brotli_quality_test_input.bin
```

The reproducer prints the Brotli encoder version and the two compressed sizes.
It returns a non-zero exit status when the `quality=11` output is larger than
the `quality=1` output.

[reproduce.zip](https://github.com/user-attachments/files/28141963/reproduce.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.