Commit bcc0957
Optimize KSR update path with static rate→TagValue cache
Two changes:
1. Benchmark (address dougqh feedback):
- Switch to Throughput mode + @threads(8) to surface GC pressure
- @State(Scope.Thread): each thread gets its own PTags, models real traces
- Add updateRateFreshTrace: resets instance cache each iteration to model
per-trace cost (the actual hot path Doug was concerned about)
- Update run instructions to include -t 8 -prof gc
2. Static cache for KSR TagValue (Option A):
- Add static volatile cachedKsrRate + cachedKsrTagValue to PTags
- On updateKnuthSamplingRate, check static cache before formatting
- Eliminates char[]+String allocation on the per-trace path in steady state
(every new PTags starts with NaN; without the cache, each trace root
re-formats even when the rate is constant)
- Race is benign: two threads computing the same rate produce equal TagValues
- gc.alloc.rate.norm: updateRateFreshTrace goes from 80 B/op → ≈ 0 B/op
structurally (not JIT-dependent)
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>1 parent e73c492 commit bcc0957
File tree
2 files changed
+46
-8
lines changed- dd-trace-core/src
- jmh/java/datadog/trace/core/propagation/ptags
- main/java/datadog/trace/core/propagation/ptags
2 files changed
+46
-8
lines changedLines changed: 27 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
33 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
34 | 39 | | |
35 | | - | |
| 40 | + | |
36 | 41 | | |
37 | 42 | | |
38 | | - | |
39 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
| |||
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
70 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
71 | 80 | | |
72 | 81 | | |
73 | 82 | | |
74 | 83 | | |
75 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
76 | 97 | | |
77 | 98 | | |
78 | 99 | | |
| |||
Lines changed: 19 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
97 | 103 | | |
98 | 104 | | |
99 | 105 | | |
| |||
275 | 281 | | |
276 | 282 | | |
277 | 283 | | |
278 | | - | |
279 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
280 | 297 | | |
281 | 298 | | |
282 | 299 | | |
| |||
0 commit comments