chopratejas commited on
Commit
e8fad1d
Β·
1 Parent(s): 51faf9b

Update benchmarks with real production telemetry and compression data

Browse files

- Added compression performance table (6 content types, 1-2ms latency)
- Added production telemetry: 52ms median overhead, 50K+ sessions
- Added pipeline step timing from real-world data
- Added fleet summary (249 instances, 1.4B tokens saved)
- Added honest Limitations section (what we don't compress)
- Removed stale multi-tool agent test (script missing)

Files changed (1) hide show
  1. docs/benchmarks.md +116 -115
docs/benchmarks.md CHANGED
@@ -1,141 +1,163 @@
1
- # Accuracy Benchmarks
2
 
3
- Headroom's core promise: **compress context without losing accuracy**. This page shows our latest benchmark results against established open-source datasets.
4
 
5
- !!! success "Key Result"
6
- **98.2% recall** on article extraction with **94.9% compression** β€” we preserve nearly all information while dramatically reducing tokens.
 
7
 
8
  ---
9
 
10
- ## Summary
11
 
12
- | Benchmark | Metric | Headroom | Baseline | Status |
13
- |-----------|--------|----------|----------|--------|
14
- | [Scrapinghub Article Extraction](#html-extraction) | F1 Score | **0.919** | 0.958 | :white_check_mark: |
15
- | [Scrapinghub Article Extraction](#html-extraction) | Recall | **98.2%** | β€” | :white_check_mark: |
16
- | [Scrapinghub Article Extraction](#html-extraction) | Compression | **94.9%** | β€” | :white_check_mark: |
17
- | [SmartCrusher (JSON)](#json-compression) | Accuracy | **100%** | β€” | :white_check_mark: |
18
- | [SmartCrusher (JSON)](#json-compression) | Compression | **87.6%** | β€” | :white_check_mark: |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  ---
21
 
22
- ## HTML Extraction
 
 
23
 
24
  **Dataset**: [Scrapinghub Article Extraction Benchmark](https://huggingface.co/datasets/allenai/scrapinghub-article-extraction-benchmark)
25
  **Samples**: 181 HTML pages with ground truth article bodies
26
  **Baseline**: trafilatura (0.958 F1)
27
 
28
- HTMLExtractor removes scripts, styles, navigation, ads, and boilerplate while preserving article content.
29
-
30
- ### Results
31
-
32
  | Metric | Value | Description |
33
- |--------|-------|-------------|
34
  | **F1 Score** | 0.919 | Token-level overlap with ground truth |
35
  | **Precision** | 0.879 | Proportion of extracted content that's relevant |
36
  | **Recall** | 0.982 | Proportion of ground truth content captured |
37
  | **Compression** | 94.9% | Average size reduction |
38
 
39
- ### Why Recall Matters Most
40
-
41
- For LLM applications, **recall is critical** β€” we must capture all relevant information. A 98.2% recall means:
42
-
43
- - Nearly all article content is preserved
44
- - LLMs can answer questions accurately from extracted content
45
- - The slight precision drop (some extra content) doesn't hurt LLM accuracy
46
-
47
- ### Run It Yourself
48
 
49
  ```bash
50
- # Install dependencies
51
  pip install "headroom-ai[html]" datasets
52
-
53
- # Run the benchmark
54
  pytest tests/test_evals/test_html_oss_benchmarks.py::TestExtractionBenchmark -v -s
55
  ```
56
 
57
- ---
58
-
59
- ## JSON Compression (SmartCrusher)
60
 
61
  **Test**: 100 production log entries with critical error at position 67
62
  **Task**: Find the error, error code, resolution, and affected count
63
 
64
- ### Results
65
-
66
  | Metric | Baseline | Headroom |
67
- |--------|----------|----------|
68
  | Input tokens | 10,144 | 1,260 |
69
  | Correct answers | 4/4 | **4/4** |
70
  | Compression | β€” | **87.6%** |
71
 
72
- SmartCrusher preserves:
73
-
74
- - First N items (schema examples)
75
- - Last N items (recency)
76
- - All anomalies (errors, warnings, outliers)
77
- - Statistical distribution
78
-
79
- ### Run It Yourself
80
-
81
- ```bash
82
- python examples/needle_in_haystack_test.py
83
- ```
84
-
85
- ---
86
-
87
- ## QA Accuracy Preservation
88
-
89
- We verify that LLMs can answer questions equally well from compressed content.
90
-
91
- **Method**:
92
- 1. Take original HTML content
93
- 2. Extract with HTMLExtractor
94
- 3. Ask LLM same question on both
95
- 4. Compare answers against ground truth
96
-
97
- **Datasets**: SQuAD v2, HotpotQA
98
 
99
- ### Results
100
 
101
  | Metric | Original HTML | Extracted | Delta |
102
- |--------|---------------|-----------|-------|
103
  | F1 Score | 0.85 | 0.87 | +0.02 |
104
  | Exact Match | 60% | 62% | +2% |
105
 
106
  !!! note "Extraction Can Improve Accuracy"
107
  Removing HTML noise sometimes *helps* LLMs focus on relevant content.
108
 
109
- ### Run It Yourself
110
 
111
- ```bash
112
- # Requires OPENAI_API_KEY
113
- pytest tests/test_evals/test_html_oss_benchmarks.py::TestQAAccuracyPreservation -v -s
114
- ```
115
 
116
- ---
117
 
118
- ## Multi-Tool Agent Test
 
 
 
 
119
 
120
- **Setup**: Agno agent with 4 tools investigating a memory leak
121
- **Total tool output**: 62,323 chars (~15,580 tokens)
122
 
123
- ### Results
 
 
 
124
 
125
- | Metric | Baseline | Headroom |
126
- |--------|----------|----------|
127
- | Tokens sent | 15,662 | 6,100 |
128
- | Tool calls | 4 | 4 |
129
- | Correct findings | All | **All** |
130
- | Compression | β€” | **76.3%** |
131
 
132
- Both found: Issue #42, `cleanup_worker()` fix, OutOfMemoryError logs, relevant papers.
 
 
 
133
 
134
- ### Run It Yourself
135
 
136
- ```bash
137
- python examples/multi_tool_agent_test.py
138
- ```
139
 
140
  ---
141
 
@@ -143,21 +165,12 @@ python examples/multi_tool_agent_test.py
143
 
144
  ### Token-Level F1
145
 
146
- We use the standard NLP metric for text overlap:
147
-
148
  ```
149
  Precision = |predicted ∩ ground_truth| / |predicted|
150
  Recall = |predicted ∩ ground_truth| / |ground_truth|
151
  F1 = 2 * (Precision * Recall) / (Precision + Recall)
152
  ```
153
 
154
- ### QA Accuracy
155
-
156
- For question-answering, we measure:
157
-
158
- - **Exact Match**: Normalized answer strings match exactly
159
- - **F1 Score**: Token overlap between predicted and ground truth answers
160
-
161
  ### Compression Ratio
162
 
163
  ```
@@ -166,12 +179,17 @@ Compression = 1 - (compressed_size / original_size)
166
 
167
  A 94.9% compression means the output is 5.1% of the original size.
168
 
 
 
 
 
 
 
 
169
  ---
170
 
171
  ## Reproducing Results
172
 
173
- All benchmarks are reproducible:
174
-
175
  ```bash
176
  # Clone the repo
177
  git clone https://github.com/chopratejas/headroom.git
@@ -183,23 +201,6 @@ pip install -e ".[evals,html]"
183
  # Run all benchmarks
184
  pytest tests/test_evals/ -v -s
185
 
186
- # Run specific benchmark
187
- pytest tests/test_evals/test_html_oss_benchmarks.py -v -s
188
  ```
189
-
190
- ### CI Integration
191
-
192
- Benchmarks run on every PR. See [.github/workflows/ci.yml](https://github.com/chopratejas/headroom/blob/main/.github/workflows/ci.yml).
193
-
194
- ---
195
-
196
- ## Adding New Benchmarks
197
-
198
- We welcome contributions! See [CONTRIBUTING.md](https://github.com/chopratejas/headroom/blob/main/CONTRIBUTING.md) for guidelines.
199
-
200
- Benchmarks should:
201
-
202
- 1. Use established open-source datasets
203
- 2. Include reproducible evaluation code
204
- 3. Test accuracy preservation, not just compression
205
- 4. Run in CI without API keys (or skip gracefully)
 
1
+ # Benchmarks
2
 
3
+ Headroom's core promise: **compress context without losing accuracy**. This page shows accuracy benchmarks, compression performance, and real-world production telemetry from 250+ active proxy instances.
4
 
5
+ !!! success "Key Results"
6
+ **98.2% recall** on article extraction with **94.9% compression**.
7
+ **52ms median overhead** in production. **1.4 billion tokens saved** across 249 instances.
8
 
9
  ---
10
 
11
+ ## Compression Performance
12
 
13
+ Tested on Apple M-series (CPU), headroom v0.5.18. Each test runs `compress()` on realistic tool outputs.
14
+
15
+ | Content Type | Original | Compressed | Saved | Ratio | Latency |
16
+ |---|---|---|---|---|---|
17
+ | JSON array (100 items) | 3,163 | 297 | 2,866 | **90.6%** | 1ms |
18
+ | JSON array (500 items) | 9,526 | 1,614 | 7,912 | **83.1%** | 2ms |
19
+ | Shell output (200 lines) | 3,238 | 469 | 2,769 | **85.5%** | 1ms |
20
+ | Build log (200 lines) | 2,412 | 148 | 2,264 | **93.9%** | 1ms |
21
+ | grep results (150 hits) | 2,624 | 2,624 | 0 | 0.0% | <1ms |
22
+ | Python source (~480 lines) | 2,958 | 2,958 | 0 | 0.0% | <1ms |
23
+ | **Total** | **23,921** | **8,110** | **15,811** | **66.1%** | **5ms** |
24
+
25
+ **Notes:**
26
+
27
+ - grep results and Python source show 0% compression β€” these are already compact structured formats. SmartCrusher only compresses JSON arrays; code passes through to preserve correctness.
28
+ - Latency is for the `compress()` SDK call, not the full proxy round-trip.
29
+
30
+ ---
31
+
32
+ ## Production Telemetry
33
+
34
+ Real-world data from **50,000+ proxy sessions** across 250+ unique instances (March 30 – April 2, 2026). Collected via anonymous telemetry beacon (opt-out: `HEADROOM_TELEMETRY=off`).
35
+
36
+ ### Proxy Overhead
37
+
38
+ | Percentile | Latency |
39
+ |---|---|
40
+ | **Median (P50)** | **52ms** |
41
+ | P90 | 309ms |
42
+ | P99 | 4,172ms |
43
+ | Mean | 161ms |
44
+
45
+ The median 52ms overhead is negligible compared to LLM inference time (typically 2-10 seconds).
46
+
47
+ ### Compression Rate
48
+
49
+ | Percentile | Compression |
50
+ |---|---|
51
+ | P25 | 4.8% |
52
+ | **Median** | **4.8%** |
53
+ | P75 | 6.9% |
54
+ | Mean | 11.3% |
55
+
56
+ Median compression is modest because many requests are short conversational turns. Heavy tool-use sessions (file reads, shell output) see 40-80% compression.
57
+
58
+ ### Pipeline Step Timing (Production Median)
59
+
60
+ | Step | Median | P90 | Description |
61
+ |---|---|---|---|
62
+ | `pipeline_total` | **16.9ms** | 289ms | Full compression pipeline |
63
+ | `content_router` | 11.7ms | 259ms | Content detection + routing |
64
+ | `compressor:smart_crusher` | 50.1ms | 50ms | JSON array compression |
65
+ | `compressor:text` | 32.0ms | 576ms | Text compression (Kompress ONNX) |
66
+ | `compressor:mixed` | 316ms | 428ms | Mixed content compression |
67
+ | `compressor:code_aware` | 815ms | 886ms | Tree-sitter AST compression |
68
+ | `_initial_token_count` | 2.9ms | 16ms | Token counting (tiktoken) |
69
+ | `_deep_copy` | 0.1ms | 0.3ms | Message copy overhead |
70
+
71
+ ### Fleet Summary
72
+
73
+ | Metric | Value |
74
+ |---|---|
75
+ | Clean instances | 249 |
76
+ | Total tokens saved | 1.4 billion |
77
+ | Total $ saved | ~$4,000 |
78
+ | OS distribution | Linux 57%, macOS 38%, Windows 5% |
79
+ | Top version | 0.5.17 (77%) |
80
+ | Models used | Claude Opus 4.6, Sonnet 4.6, Haiku 4.5 |
81
 
82
  ---
83
 
84
+ ## Accuracy Benchmarks
85
+
86
+ ### HTML Extraction
87
 
88
  **Dataset**: [Scrapinghub Article Extraction Benchmark](https://huggingface.co/datasets/allenai/scrapinghub-article-extraction-benchmark)
89
  **Samples**: 181 HTML pages with ground truth article bodies
90
  **Baseline**: trafilatura (0.958 F1)
91
 
 
 
 
 
92
  | Metric | Value | Description |
93
+ |---|---|---|
94
  | **F1 Score** | 0.919 | Token-level overlap with ground truth |
95
  | **Precision** | 0.879 | Proportion of extracted content that's relevant |
96
  | **Recall** | 0.982 | Proportion of ground truth content captured |
97
  | **Compression** | 94.9% | Average size reduction |
98
 
99
+ For LLM applications, **recall is critical** β€” 98.2% means nearly all article content is preserved. The slight precision drop (some extra content) doesn't hurt LLM accuracy.
 
 
 
 
 
 
 
 
100
 
101
  ```bash
102
+ # Run it yourself
103
  pip install "headroom-ai[html]" datasets
 
 
104
  pytest tests/test_evals/test_html_oss_benchmarks.py::TestExtractionBenchmark -v -s
105
  ```
106
 
107
+ ### JSON Compression (SmartCrusher)
 
 
108
 
109
  **Test**: 100 production log entries with critical error at position 67
110
  **Task**: Find the error, error code, resolution, and affected count
111
 
 
 
112
  | Metric | Baseline | Headroom |
113
+ |---|---|---|
114
  | Input tokens | 10,144 | 1,260 |
115
  | Correct answers | 4/4 | **4/4** |
116
  | Compression | β€” | **87.6%** |
117
 
118
+ SmartCrusher preserves first N items (schema), last N items (recency), all anomalies (errors, warnings), and statistical distribution.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
+ ### QA Accuracy Preservation
121
 
122
  | Metric | Original HTML | Extracted | Delta |
123
+ |---|---|---|---|
124
  | F1 Score | 0.85 | 0.87 | +0.02 |
125
  | Exact Match | 60% | 62% | +2% |
126
 
127
  !!! note "Extraction Can Improve Accuracy"
128
  Removing HTML noise sometimes *helps* LLMs focus on relevant content.
129
 
130
+ ---
131
 
132
+ ## Limitations
 
 
 
133
 
134
+ ### What Headroom Does NOT Compress
135
 
136
+ - **Short messages** (< 300 tokens) β€” overhead exceeds savings
137
+ - **Source code** β€” passes through unchanged to preserve correctness (unless tree-sitter AST compression is enabled)
138
+ - **grep/search results** β€” compact structured format, already minimal
139
+ - **Images** β€” counted at fixed token cost (~1,600 tokens), not compressed as text
140
+ - **System prompts** β€” preserved for prefix cache compatibility
141
 
142
+ ### Known Overhead Sources
 
143
 
144
+ - **Token counting** (P90: 16ms) β€” runs tiktoken twice (before + after compression)
145
+ - **Tree-sitter AST parsing** (P90: 886ms) β€” expensive for large code files
146
+ - **Kompress ONNX** (P90: 576ms) β€” ML inference on CPU for text compression
147
+ - **Content detection** (Magika) β€” ML classification of content type
148
 
149
+ ### When Headroom Adds the Most Value
 
 
 
 
 
150
 
151
+ - **Long agent sessions** with accumulated tool outputs (40-80% compression)
152
+ - **JSON-heavy workflows** (API responses, database queries) β€” 83-94% compression
153
+ - **Build/test output** β€” 85-94% compression
154
+ - **Multi-tool agents** β€” 60-76% compression across tool results
155
 
156
+ ### When Headroom Adds Little Value
157
 
158
+ - **Short conversational exchanges** β€” median 4.8% compression
159
+ - **Code-only sessions** (reading/writing files) β€” code passes through
160
+ - **Single-turn requests** β€” no accumulated context to compress
161
 
162
  ---
163
 
 
165
 
166
  ### Token-Level F1
167
 
 
 
168
  ```
169
  Precision = |predicted ∩ ground_truth| / |predicted|
170
  Recall = |predicted ∩ ground_truth| / |ground_truth|
171
  F1 = 2 * (Precision * Recall) / (Precision + Recall)
172
  ```
173
 
 
 
 
 
 
 
 
174
  ### Compression Ratio
175
 
176
  ```
 
179
 
180
  A 94.9% compression means the output is 5.1% of the original size.
181
 
182
+ ### Production Telemetry
183
+
184
+ - Collected via anonymous beacon (no prompts, no content, no PII)
185
+ - Image-inflated instances excluded (base64 counted as text tokens β€” fixed in v0.5.18)
186
+ - Multi-worker beacon spam excluded (per-instance MAX, not SUM)
187
+ - Opt-out: `HEADROOM_TELEMETRY=off`
188
+
189
  ---
190
 
191
  ## Reproducing Results
192
 
 
 
193
  ```bash
194
  # Clone the repo
195
  git clone https://github.com/chopratejas/headroom.git
 
201
  # Run all benchmarks
202
  pytest tests/test_evals/ -v -s
203
 
204
+ # Run compression benchmark
205
+ python -c "from headroom import compress; print(compress([{'role':'user','content':'test'}]))"
206
  ```