Commit 453ddfc
fix(pkg/aggregator): gate hookBatch append on HasSubscribers()
The unconditional append inside sample() was copying a 72-byte
MetricSampleSnapshot struct on every DogStatsD metric even when no
observer was listening. SMP profiler comparison (main vs branch with
0 subscribers) showed +12ms in (*TimeSampler).sample() from this copy
alone.
Gating on HasSubscribers() makes the idle path (0 subscribers) match
main exactly: one atomic read, then nothing. The append only runs when
someone is actually subscribed.
Before: noop/0sub/1sub/5sub all ~82 ns (append unconditional)
After: noop/0sub ~77 ns; 1sub ~82 ns; 5sub ~86 ns
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>1 parent 17b9bb1 commit 453ddfc
1 file changed
Lines changed: 10 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
| |||
0 commit comments