Commit e2258ca
perf(precompute): jemalloc global allocator + Arc<str> group-key interning
Two CPU optimizations for the precompute engine hot path, motivated by
profiling the tumbling-window KLL sketch workload (perf -F499, 4000 groups).
1. jemalloc global allocator (tikv-jemallocator, default `jemalloc` feature).
The hot path was dominated by malloc/free churn (43% of CPU) from
per-window sketch buffers. jemalloc's per-thread arenas / size-class
caching recycle those buffers, dropping allocator cost to ~7%.
2. Arc<str> group-key interning. group_states is now nested
HashMap<u64, HashMap<Arc<str>, GroupState>>, so the per-sample/per-batch
lookup borrows by &str with zero allocation; the key string is allocated
once per group. Also removes a redundant per-batch hashmap lookup in
process_group_samples.
Measured (4000 groups, 2.4M window-closes, mean of 3 reps), relative to the
pre-PR clone+system-malloc baseline:
clone + system malloc 7.95s 301k closes/s 1.00x
move (into_accumulator) 6.33s 380k closes/s 1.26x
move + jemalloc 3.71s 646k closes/s 2.14x
move + jemalloc + Arc<str> 3.61s 665k closes/s 2.20x
All 473 lib tests pass.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 1f2487e commit e2258ca
4 files changed
Lines changed: 86 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
| |||
87 | 93 | | |
88 | 94 | | |
89 | 95 | | |
90 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
91 | 99 | | |
92 | 100 | | |
93 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
1 | 9 | | |
2 | 10 | | |
3 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
| |||
185 | 189 | | |
186 | 190 | | |
187 | 191 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
200 | 198 | | |
201 | 199 | | |
202 | 200 | | |
203 | 201 | | |
204 | 202 | | |
205 | | - | |
206 | | - | |
| 203 | + | |
207 | 204 | | |
208 | 205 | | |
209 | 206 | | |
| |||
240 | 237 | | |
241 | 238 | | |
242 | 239 | | |
243 | | - | |
| 240 | + | |
244 | 241 | | |
245 | 242 | | |
246 | 243 | | |
| |||
264 | 261 | | |
265 | 262 | | |
266 | 263 | | |
267 | | - | |
| 264 | + | |
268 | 265 | | |
269 | 266 | | |
270 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
271 | 273 | | |
272 | 274 | | |
273 | 275 | | |
274 | 276 | | |
275 | 277 | | |
276 | 278 | | |
277 | 279 | | |
278 | | - | |
279 | | - | |
280 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
281 | 288 | | |
282 | 289 | | |
283 | | - | |
| 290 | + | |
284 | 291 | | |
285 | 292 | | |
286 | 293 | | |
287 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
288 | 298 | | |
289 | | - | |
| 299 | + | |
290 | 300 | | |
291 | | - | |
| 301 | + | |
292 | 302 | | |
293 | 303 | | |
294 | 304 | | |
| |||
305 | 315 | | |
306 | 316 | | |
307 | 317 | | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
319 | 328 | | |
320 | 329 | | |
321 | 330 | | |
| |||
470 | 479 | | |
471 | 480 | | |
472 | 481 | | |
| 482 | + | |
473 | 483 | | |
474 | 484 | | |
475 | 485 | | |
| |||
484 | 494 | | |
485 | 495 | | |
486 | 496 | | |
487 | | - | |
| 497 | + | |
| 498 | + | |
488 | 499 | | |
489 | 500 | | |
490 | 501 | | |
| |||
523 | 534 | | |
524 | 535 | | |
525 | 536 | | |
| 537 | + | |
526 | 538 | | |
527 | 539 | | |
528 | 540 | | |
| |||
0 commit comments