Commit 89a4f25
authored
The Line Protocol parser's tokenizer appended bytes one-at-a-time into a growing []byte per part, allocating a fresh backing array for every space and every comma split in every line-protocol line. Replaced with sub-slice indexing: track a `start` index, emit `data[start:i]` sub-slices on delimiter hits, return slices that alias the input buffer.
Behavior unchanged at all edges (consecutive/leading/trailing delimiters, escape pairs, quote tracking, empty input). Aliasing safe because every downstream caller copies via string(...) or unescape() before storage — no []byte references escape the parse call.
Bench (Apple M3 Max, telegraf line + 10-line batch):
- ParseLine: 1547 ns → 915 ns (-41% ns, -52% allocs)
- ParseBatch: 9215 ns → 6326 ns (-31% ns, -50% allocs)
Additional optimizations landed in the same PR:
- Pre-sized parts slice (cap=4) — first append allocation-free
- Empty-input fast path (Gemini R1) — defensive guard
- Lazy parts allocation (Gemini R2) — no-delimiter inputs return 1-element literal instead of cap=4 (-720 B / -6.6% on ParseBatch)
Declined with bench evidence: dynamic cap=8 on comma path (Gemini R1) regressed the full path +9% / +1.9 KB because most production comma-splits have ≤4 parts.
BenchmarkSplitOnDelimiter added covering both delimiter paths so future regressions don't slip past CI.
3 Gemini rounds (R3 clean pass). All 33 line-protocol tests pass under -race × 2.
1 parent c1ef424 commit 89a4f25
2 files changed
Lines changed: 79 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
149 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
150 | 178 | | |
151 | | - | |
| 179 | + | |
152 | 180 | | |
153 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
154 | 187 | | |
155 | 188 | | |
156 | | - | |
157 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
158 | 192 | | |
159 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
160 | 196 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
166 | 205 | | |
167 | | - | |
168 | | - | |
| 206 | + | |
169 | 207 | | |
170 | 208 | | |
171 | 209 | | |
172 | | - | |
173 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
174 | 217 | | |
175 | 218 | | |
176 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
560 | 560 | | |
561 | 561 | | |
562 | 562 | | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
0 commit comments