You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚠️ AI-generated issue — requires human investigation before acting on it.
Summary
Bucket::add in src/collector.rs uses for_each to scan all existing entries for a matching key, but does not short-circuit after finding a match. Since bucket entries are unique, at most one match can exist, so all iterations after the match are wasted work. This runs in the hot signal-handler path on every sample.
Location
src/collector.rs, lines 50–55:
self.entries[0..self.length].iter_mut().for_each(|ele| {if ele.item == key {
ele.count += count;
done = true;// ← sets flag but loop continues}});
Impact
With BUCKETS_ASSOCIATIVITY = 4, the maximum wasted iterations is 3 per sample in the hit case. This is minor in isolation but accumulates at high sampling frequencies (e.g. 999 Hz in the test suite) and could be avoided at zero cost.
Expected behaviour
Use a find/position-style loop with an early exit, e.g.:
Summary
Bucket::addinsrc/collector.rsusesfor_eachto scan all existing entries for a matching key, but does not short-circuit after finding a match. Since bucket entries are unique, at most one match can exist, so all iterations after the match are wasted work. This runs in the hot signal-handler path on every sample.Location
src/collector.rs, lines 50–55:Impact
With
BUCKETS_ASSOCIATIVITY = 4, the maximum wasted iterations is 3 per sample in the hit case. This is minor in isolation but accumulates at high sampling frequencies (e.g. 999 Hz in the test suite) and could be avoided at zero cost.Expected behaviour
Use a
find/position-style loop with an early exit, e.g.: