Run them with:
npm run bench # builds dist/, then runs bench/run.mjs with tinybench
The suite measures the built package (dist/) on four workloads:
file-tests-props.aseprite from Aseprite's test suite (64×64, 4 layers, 6 frames).These were measured on Node 26 on Apple Silicon. Numbers are the mean in ms per operation; lower is better.
| Benchmark | Initial port | Optimized | Speedup |
|---|---|---|---|
| small: read | 0.366 | 0.092 | 4.0× |
| small: read + write | 0.888 | 0.184 | 4.8× |
| large: read | 110.6 | 89.4 | 1.2× |
| large: write after read (reuses compressed data) | 154.1 | 59.6 | 2.6× |
| large: write new (deflate every cel, level 6) | 482.7 | 477.4 | — |
large: write new, compressionLevel: 1 |
— | 287.7 | 1.7× vs level 6 |
| many frames: read | 145.6 | 9.7 | 15× |
| many frames: write after read | 2,098.8 | 9.2 | 229× |
w × h × bytes per pixel), as Aseprite does, instead of a buffer that grows as it goes.Writing brand-new pixel data is dominated by deflate (fflate, pure JS). If speed matters more than size, file.write({ compressionLevel: 1 }) is about 1.7× faster and produces files about 2.5× larger. Level 6, the default, matches Aseprite.
To write an unmodified file back byte for byte, the writer reuses each cel's, tilemap's and tileset's original zlib stream when the decoded data still matches it. Deciding that must be exact: 0.1.0 compared only Adler-32 checksums, and a colliding edit was silently discarded (#11).
The reader stores each decoded buffer behind an accessor property (pixels.data, tiles, a tileset's pixels) that records when it is first read or assigned. Until then, no code outside the library has a reference to the buffer, so it cannot have changed, and the writer reuses the original stream with no work at all. Once the buffer has been handed out, the writer checks it exactly: an Adler-32 comparison rejects most edits cheaply, and when the checksums agree, the original stream is decompressed and compared byte for byte. Copying the object (for example { ...pixels } or structuredClone) counts as reading it.
This adds no memory: nothing is copied or cached. The cost is a small, fixed setup per cel when reading, about 0.6 µs, which shows up only on files with thousands of tiny cels.
Measured on Node 26 (Apple Silicon), mean ms per operation:
| Benchmark | Exact check on every write | Accessor tracking |
|---|---|---|
| medium: read | 28.6 | 27.9 |
| medium: write after read | 46.3 | 0.70 |
| medium: write after reading every cel's pixels | 46.3 | 40.3 |
| large: write after read | 240.7 | 1.78 |
| many frames: read | 43.2 | 46.5 |
| many frames: write after read | 54.5 | 6.6 |
A copy of the decoded pixels taken at read time would make the "write after reading every cel's pixels" case about as fast as an untouched write, but it doubles the memory held for pixels, so it isn't used.