defuss-brotli 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -52
- package/dist/compressor.js +2 -2
- package/dist/decompressor.js +2 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -65,12 +65,12 @@ valid UTF-8, replacement characters (U+FFFD) are inserted rather than throwing.
|
|
|
65
65
|
|
|
66
66
|
```ts
|
|
67
67
|
interface BrotliCompressOptions {
|
|
68
|
-
quality?: number; // 0
|
|
69
|
-
lgwin?: number; // 10
|
|
68
|
+
quality?: number; // 0-11, default 6
|
|
69
|
+
lgwin?: number; // 10-24, default 22
|
|
70
70
|
}
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
- **`quality`** - 0 is fastest/largest, 11 is slowest/smallest. 5
|
|
73
|
+
- **`quality`** - 0 is fastest/largest, 11 is slowest/smallest. 5-7 is the sweet spot for on-the-fly web serving.
|
|
74
74
|
- **`lgwin`** - Sliding window size exponent. Larger windows find more matches at the cost of memory. 22 covers most web-text repetition patterns.
|
|
75
75
|
|
|
76
76
|
### Decompression Options
|
|
@@ -99,8 +99,8 @@ Hard cap on decompressed output to prevent **decompression bombs**. Raise explic
|
|
|
99
99
|
|
|
100
100
|
### Limits
|
|
101
101
|
|
|
102
|
-
- `quality` must be an integer in **0
|
|
103
|
-
- `lgwin` must be an integer in **10
|
|
102
|
+
- `quality` must be an integer in **0-11** (Brotli spec hard limit).
|
|
103
|
+
- `lgwin` must be an integer in **10-24** (Brotli spec hard limit).
|
|
104
104
|
- `maxOutputSize` defaults to **64 MiB** - the WASM module rejects output exceeding this.
|
|
105
105
|
- Browser WASM memory is capped at **~2 GB** on 64-bit platforms (practical upper bound for very large payloads).
|
|
106
106
|
|
|
@@ -128,59 +128,59 @@ bun run bench:browser # Chromium via Playwright
|
|
|
128
128
|
|
|
129
129
|
### Node.js (Bun)
|
|
130
130
|
|
|
131
|
-
**Text Compression
|
|
131
|
+
**Text Compression - `compressText`** (ops/sec, higher is better):
|
|
132
132
|
|
|
133
133
|
| Payload | Quality 1 | Quality 6 | Quality 11 |
|
|
134
134
|
|---|---|---|---|
|
|
135
|
-
| Short JSON (83 B) |
|
|
136
|
-
| Markdown (2 KB) |
|
|
137
|
-
| HTML (8 KB) | 5,
|
|
135
|
+
| Short JSON (83 B) | - | 37,239 | - |
|
|
136
|
+
| Markdown (2 KB) | 19,819 | 10,141 | 404 |
|
|
137
|
+
| HTML (8 KB) | 5,191 | 2,704 | 18 |
|
|
138
138
|
|
|
139
|
-
**Binary Compression
|
|
139
|
+
**Binary Compression - `compress`** (ops/sec):
|
|
140
140
|
|
|
141
141
|
| Payload | Quality 1 | Quality 6 | Quality 11 |
|
|
142
142
|
|---|---|---|---|
|
|
143
|
-
| Pseudorandom (512 B) |
|
|
144
|
-
| SVG (4.9 MB) | 8.
|
|
145
|
-
| PNG (2.1 MB) | 39.
|
|
143
|
+
| Pseudorandom (512 B) | - | 29,430 | - |
|
|
144
|
+
| SVG (4.9 MB) | 8.0 | 4.0 | 0.15 |
|
|
145
|
+
| PNG (2.1 MB) | 39.6 | 82.8 | 0.21 |
|
|
146
146
|
|
|
147
147
|
PNG compresses faster than SVG at q6 because already-compressed data triggers
|
|
148
148
|
Brotli's fast-path fallback earlier, producing less work per byte.
|
|
149
149
|
|
|
150
|
-
**Text Decompression
|
|
150
|
+
**Text Decompression - `decompressText`** (ops/sec):
|
|
151
151
|
|
|
152
152
|
| Payload | ops/sec |
|
|
153
153
|
|---|---|
|
|
154
|
-
| Short JSON (83 B) |
|
|
155
|
-
| Markdown (2 KB) |
|
|
156
|
-
| HTML (8 KB) |
|
|
154
|
+
| Short JSON (83 B) | 141,241 |
|
|
155
|
+
| Markdown (2 KB) | 47,757 |
|
|
156
|
+
| HTML (8 KB) | 37,288 |
|
|
157
157
|
|
|
158
|
-
**Binary Decompression
|
|
158
|
+
**Binary Decompression - `decompress`** (ops/sec):
|
|
159
159
|
|
|
160
160
|
| Payload | ops/sec |
|
|
161
161
|
|---|---|
|
|
162
|
-
| Pseudorandom (512 B) |
|
|
163
|
-
| SVG (4.9 MB) |
|
|
164
|
-
| PNG (2.1 MB) |
|
|
162
|
+
| Pseudorandom (512 B) | 115,493 |
|
|
163
|
+
| SVG (4.9 MB) | 30.7 |
|
|
164
|
+
| PNG (2.1 MB) | 699 |
|
|
165
165
|
|
|
166
166
|
### Browser (Chromium)
|
|
167
167
|
|
|
168
|
-
**Text Compression
|
|
168
|
+
**Text Compression - `compressText`** (ops/sec, higher is better):
|
|
169
169
|
|
|
170
170
|
| Payload | Quality 1 | Quality 6 | Quality 11 |
|
|
171
171
|
|---|---|---|---|
|
|
172
|
-
| Short JSON (83 B) |
|
|
172
|
+
| Short JSON (83 B) | - | 36,264 | - |
|
|
173
173
|
| Markdown (2 KB) | 36,002 | 12,932 | 408 |
|
|
174
174
|
| HTML (8 KB) | 8,222 | 2,535 | 19 |
|
|
175
175
|
|
|
176
|
-
**Binary Compression
|
|
176
|
+
**Binary Compression - `compress`** (ops/sec):
|
|
177
177
|
|
|
178
178
|
| Payload | Quality 1 | Quality 6 | Quality 11 |
|
|
179
179
|
|---|---|---|---|
|
|
180
|
-
| Pseudorandom (512 B) |
|
|
180
|
+
| Pseudorandom (512 B) | - | 29,712 | - |
|
|
181
181
|
| SVG (4.9 MB) | 15.9 | 4.8 | 0.15 |
|
|
182
182
|
|
|
183
|
-
**Text Decompression
|
|
183
|
+
**Text Decompression - `decompressText`** (ops/sec):
|
|
184
184
|
|
|
185
185
|
| Payload | ops/sec |
|
|
186
186
|
|---|---|
|
|
@@ -188,7 +188,7 @@ Brotli's fast-path fallback earlier, producing less work per byte.
|
|
|
188
188
|
| Markdown (2 KB) | 51,946 |
|
|
189
189
|
| HTML (8 KB) | 35,990 |
|
|
190
190
|
|
|
191
|
-
**Binary Decompression
|
|
191
|
+
**Binary Decompression - `decompress`** (ops/sec):
|
|
192
192
|
|
|
193
193
|
| Payload | ops/sec |
|
|
194
194
|
|---|---|
|
|
@@ -211,45 +211,45 @@ Sample output:
|
|
|
211
211
|
Short JSON (~83 B) (83 B input)
|
|
212
212
|
════════════════════════════════════════════════════════════════════════
|
|
213
213
|
Quality │ Output │ Ratio │ Compress ms │ Decompress ms
|
|
214
|
-
|
|
215
|
-
1 │ 87 B │ 104.8% │ 1.
|
|
216
|
-
4 │ 83 B │ 100.0% │ 0.
|
|
217
|
-
6 │ 80 B │ 96.4% │
|
|
218
|
-
9 │ 80 B │ 96.4% │ 2.
|
|
219
|
-
11 │ 85 B │ 102.4% │ 3.
|
|
214
|
+
------- │ ---------- │ ------- │ ----------- │ -------------
|
|
215
|
+
1 │ 87 B │ 104.8% │ 1.02 │ 0.32
|
|
216
|
+
4 │ 83 B │ 100.0% │ 0.55 │ 0.74
|
|
217
|
+
6 │ 80 B │ 96.4% │ 0.67 │ 0.16
|
|
218
|
+
9 │ 80 B │ 96.4% │ 2.13 │ 0.12
|
|
219
|
+
11 │ 85 B │ 102.4% │ 3.54 │ 0.28
|
|
220
220
|
|
|
221
221
|
════════════════════════════════════════════════════════════════════════
|
|
222
222
|
Pseudorandom binary (512 B) (512 B input)
|
|
223
223
|
════════════════════════════════════════════════════════════════════════
|
|
224
224
|
Quality │ Output │ Ratio │ Compress ms │ Decompress ms
|
|
225
|
-
|
|
226
|
-
1 │ 286 B │ 55.9% │ 0.08 │ 0.
|
|
227
|
-
4 │ 278 B │ 54.3% │ 0.
|
|
228
|
-
6 │ 270 B │ 52.7% │ 0.
|
|
229
|
-
9 │ 259 B │ 50.6% │ 0.
|
|
230
|
-
11 │ 239 B │ 46.7% │
|
|
225
|
+
------- │ ---------- │ ------- │ ----------- │ -------------
|
|
226
|
+
1 │ 286 B │ 55.9% │ 0.08 │ 0.91
|
|
227
|
+
4 │ 278 B │ 54.3% │ 0.28 │ 0.06
|
|
228
|
+
6 │ 270 B │ 52.7% │ 0.27 │ 0.09
|
|
229
|
+
9 │ 259 B │ 50.6% │ 0.59 │ 0.05
|
|
230
|
+
11 │ 239 B │ 46.7% │ 2.60 │ 0.28
|
|
231
231
|
|
|
232
232
|
════════════════════════════════════════════════════════════════════════
|
|
233
233
|
SVG (4.9 MB) (4.9 MB input)
|
|
234
234
|
════════════════════════════════════════════════════════════════════════
|
|
235
235
|
Quality │ Output │ Ratio │ Compress ms │ Decompress ms
|
|
236
|
-
|
|
237
|
-
1 │ 2.8 MB │ 57.0% │
|
|
238
|
-
4 │ 1.9 MB │ 38.0% │ 85.
|
|
239
|
-
6 │ 1.8 MB │ 37.4% │
|
|
240
|
-
9 │ 1.8 MB │ 36.8% │
|
|
241
|
-
11 │ 1.7 MB │ 34.5% │
|
|
236
|
+
------- │ ---------- │ ------- │ ----------- │ -------------
|
|
237
|
+
1 │ 2.8 MB │ 57.0% │ 68.27 │ 74.07
|
|
238
|
+
4 │ 1.9 MB │ 38.0% │ 85.92 │ 43.93
|
|
239
|
+
6 │ 1.8 MB │ 37.4% │ 208.86 │ 43.04
|
|
240
|
+
9 │ 1.8 MB │ 36.8% │ 504.55 │ 42.33
|
|
241
|
+
11 │ 1.7 MB │ 34.5% │ 5093.09 │ 49.22
|
|
242
242
|
|
|
243
243
|
════════════════════════════════════════════════════════════════════════
|
|
244
244
|
PNG (2.1 MB) (2.1 MB input)
|
|
245
245
|
════════════════════════════════════════════════════════════════════════
|
|
246
246
|
Quality │ Output │ Ratio │ Compress ms │ Decompress ms
|
|
247
|
-
|
|
248
|
-
1 │ 2.1 MB │ 100.1% │
|
|
249
|
-
4 │ 2.1 MB │ 100.0% │
|
|
250
|
-
6 │ 2.1 MB │ 100.0% │ 13.
|
|
251
|
-
9 │ 2.0 MB │ 99.0% │
|
|
252
|
-
11 │ 2.0 MB │ 96.2% │
|
|
247
|
+
------- │ ---------- │ ------- │ ----------- │ -------------
|
|
248
|
+
1 │ 2.1 MB │ 100.1% │ 17.39 │ 11.60
|
|
249
|
+
4 │ 2.1 MB │ 100.0% │ 5.75 │ 11.06
|
|
250
|
+
6 │ 2.1 MB │ 100.0% │ 13.64 │ 10.74
|
|
251
|
+
9 │ 2.0 MB │ 99.0% │ 206.06 │ 23.39
|
|
252
|
+
11 │ 2.0 MB │ 96.2% │ 3162.39 │ 30.90
|
|
253
253
|
|
|
254
254
|
════════════════════════════════════════════════════════════════════════
|
|
255
255
|
All round-trips passed
|
|
@@ -259,7 +259,7 @@ Sample output:
|
|
|
259
259
|
**Key takeaways:**
|
|
260
260
|
|
|
261
261
|
- **SVG** (text-based) compresses well: 57% → 34.5% ratio as quality increases, at the cost of much longer compression times at q11.
|
|
262
|
-
- **PNG** (already compressed) barely shrinks: ~100% ratio at q1
|
|
262
|
+
- **PNG** (already compressed) barely shrinks: ~100% ratio at q1-q6, only 96% at q11 — Brotli can't improve on an already-compressed binary format.
|
|
263
263
|
- **Short text** can actually *grow* at low quality levels (104.8% at q1) — the Brotli header overhead exceeds the savings on tiny payloads.
|
|
264
264
|
|
|
265
265
|
## Defaults
|