Trending

World technology news

→
The 2016 Brotli format and a byte-count experiment on depot records
Software Engineering · 2016
Software Engineering2016

The 2016 Brotli format and a byte-count experiment on depot records

Compress the same thousand depot records with gzip and two Brotli settings, then verify that decompression reproduces the original bytes.

Archive retrospective · Topic year 2016

Developer's JournalPublished: Dec 4, 20266 min read
Reading progress0%
In this article
  1. The format and the data being measured
  2. Keeping the source bytes consistent
  3. Running the local size and round-trip check
  4. On-demand responses and static assets
  5. Moving to a representative corpus

The format and the data being measured

A depot planning screen downloads tomorrow’s inspection list as JSON. Stop identifiers change from row to row, while district names, job descriptions and service labels recur. The payload can be useful for examining a lossless format that takes advantage of repetition. RFC 7932, published in July 2016, describes the Brotli bitstream. It combines mechanisms for referring to previous output, representing symbols with variable-length codes and using a static dictionary. The format makes a decoder’s job well defined. It leaves decisions about compression effort and how to find candidate matches to the implementation. An encoder setting is therefore different from a guarantee of a particular size. We use one thousand synthetic records with repeated fields and fixed phrases so that the source input is exact, stable and easy to regenerate. The exercise compares byte counts and verifies decoded bytes. It is not a general benchmark of the compression format for arbitrary data.

Keeping the source bytes consistent

The program constructs a single UTF-8 buffer from the JSON array. All codecs see that buffer before any experimentation with shorter keys, different ordering or changes to serialization. Gzip uses the library defaults. Brotli uses text mode and explicit quality values of 4 and 9. These are options of the encoder exposed through the Node.js API. Identical-looking settings across different engines may have different costs. A payload with random-looking identifiers, compressed attachments or very short strings can behave differently from the text used here. A real HTTP request also includes overhead beyond its compressed body, and the fixture records only the lengths returned by the encoder. No timing or CPU observation is included in the comparison. This is enough to answer one well-bounded question: how much smaller the three outputs are for these exact bytes under the given local runtime and encoder choices. A later experiment can keep those choices fixed and vary the payload type.

Application flowConceptual sketch · summary of the article's technical flow

Running the local size and round-trip check

On Node.js 24.19.0 the raw UTF-8 body was 100,891 bytes. Gzip produced 3,398 bytes. Brotli quality 4 produced 1,564 bytes, and quality 9 produced 1,450. Both Brotli streams were decompressed and compared against the original buffer. The test checks byte equality so changes in ordering, encoding or punctuation remain observable. Higher quality saved another 114 bytes over quality 4 on this specific body. It does not tell us how many additional milliseconds were required, because we did not collect that measurement. The test calls synchronous functions for clarity. A server that needs to satisfy multiple concurrent visitors would have to consider event-loop delay and use integration tests with representative request sizes. Extending the test with another field is straightforward. Preserve one source buffer for every codec and report the new raw length alongside each compressed variant.

import assert from 'node:assert/strict';
import {brotliCompressSync,brotliDecompressSync,gzipSync,constants} from 'node:zlib';
const original=Buffer.from(JSON.stringify(Array.from({length:1000},(_,i)=>({
 stop:i, sector:'north-'+i%8, category:'scheduled inspection', service:'electric vehicle depot'
}))));
const compressed=[];
for(const quality of [4,9]){
 const data=brotliCompressSync(original,{params:{
  [constants.BROTLI_PARAM_QUALITY]:quality,[constants.BROTLI_PARAM_MODE]:constants.BROTLI_MODE_TEXT
 }});
 assert.deepEqual(brotliDecompressSync(data),original);
 compressed.push({quality,bytes:data.length,roundTrip:true});
}
console.log(JSON.stringify({node:process.version,source:original.length,gzip:gzipSync(original).length,brotli:compressed}));

On-demand responses and static assets

A depot report that changes once at midnight offers a different tradeoff from personalized lists generated for each reader. Static generation can absorb the encoding work during publication and serve a reusable artifact afterward. A dynamically filtered response consumes processing time per request, which makes latency as important as the saving in bytes. On HTTP, content negotiation and the response encoding must agree with what the client receives. Verify actual requests with different Accept-Encoding values through any CDN or intermediate cache in the path. The fixture exercises compression and decompression locally. It does not cover response variants, cache keys or the behavior of a browser following redirects. If you precompress a file, test the published URL with an eligible client and inspect the decoded body. Keeping the old artifact available until the new one is verified also makes a failed update recoverable without searching for a replacement representation.

Moving to a representative corpus

Test a short error response, an ordinary depot report and a large end-of-day export separately. Save a hash for each input so comparisons later use the intended bytes. Take repeated timing samples, capture raw and compressed sizes and include decoding work where it affects a target device. Separate body generation from compression when measuring server time. A useful rollout check also verifies two requests with incompatible coding preferences through the same production cache. Rate and memory measurements from the synthetic fixture are unavailable, so it cannot decide which quality is best under load. The 2016 reference describes the format used by the example, and the runtime observation describes a current Node build. Inspect real support separately when deploying to older clients or to a hosting provider that alters transport encodings. The byte counts here give one reproducible comparison against which changes to the sample itself can be checked.

886 reads ✎ Write a comment

Reader discussion

Discussion prompt

Which data would you verify before applying this development in your field?

No comments yet. Be the first to contribute.

Write a comment

Comments are real visitor contributions. Repeated, link-heavy or abusive submissions may be limited.