Skip to content
ExtendedSource checked

Brotli

Compresses web content with dictionary references and entropy coding.

Quick Facts

Compact metadata for implementation and discovery.

Category
Compression
Difficulty
Advanced
Family
Lossless Compression
Tier
Extended
Status
Verified
Review
Source Checked
Sources
1
Formulas
0
Relationships
3
Code example
Not ready
Visualization
Ready

Overview

Brotli combines LZ-style matching, a built-in dictionary, context modeling, and entropy coding for strong text compression.

Core Concepts

dictionary referenceprobability modellossless compressionsymbol representationlossless decodingstream encoding

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(n)

Average

O(n)

Worst

O(nw)

Space

O(w)

When to Use

  • Use Brotli when you need to use a sliding window and static dictionary.
  • Use it for web asset compression with inputs like byte stream.
  • Use it when the data has repetition, predictable structure, or symbol frequency imbalance.
  • Use it when the Lossless Compression tradeoff is acceptable for the problem size.

When Not to Use

  • Avoid it when small inputs or already compressed data would make metadata larger than the savings.
  • Do not treat the O(n) average case as a guarantee; check the O(nw) worst case.
  • Avoid it when the required output is not brotli compressed stream.

What It Does

  • Uses a sliding window and static dictionary
  • Entropy-codes transformed symbols

Use Cases

  • Web asset compression
  • HTTP responses
  • Text-heavy resources

Inputs

  • Byte stream
  • Compression level

Outputs

  • Brotli compressed stream

Pseudocode

  1. 1.Search for repeated sequences
  2. 2.Use dictionary entries when helpful
  3. 3.Model symbol contexts
  4. 4.Entropy-code the command stream
  5. 5.Write compressed blocks

Canonical Example

Input
text = 'AAAABBBCCDAA'
Output
compressed representation with repeated runs or shorter codes
Explanation
Brotli: The algorithm replaces predictable or repeated structure with a more compact representation.

Implementation Notes

  • Keep the input contract explicit: Byte stream; Compression level.
  • Use this step as the implementation spine: Search for repeated sequences.
  • Then preserve the next state change: Use dictionary entries when helpful.
  • Keep encoder and decoder tests paired so every compressed sample round-trips exactly.

Common Pitfalls

  • Higher Brotli quality settings can be much slower to encode but often compress better.
  • Forgetting that the decoder needs the same model, dictionary, or metadata used by the encoder.
  • Returning brotli compressed stream without handling empty, invalid, or boundary inputs.

Interactive Mechanism Walkthrough

Sequence Window & Automaton Alignment

Show web text replaced by dictionary entries and compact commands.

Input:ABABABCABAB
Window:ABAB
Step 1 of 5: Search for repeated sequences
dictionary-compression

Notes

Brotli operates in O(n) time and O(w) space within the Lossless Compression family. Often compared with Deflate and LZ77.

Sources (1)

What each reference supports for this entry.

RFC 7932

Documentation

Official Brotli compressed data format reference for LZ77, Huffman coding, contexts, and decoder behavior.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Improves onDeflate

Brotli is designed as a more modern web compression format with stronger modeling.

Brotli uses entropy coding as part of its compressed representation.

Related Algorithms

Tags

CompressionDictionary CompressionEntropy Coding