Skip to content

Commit aa4eed7

Browse files
committed
perf: use guarded stores in update_min_max to avoid cache line dirtying. Variation from PR #133, but already has macros and follow project style.
1 parent 7671dd1 commit aa4eed7

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/hdr_histogram.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,15 @@ static void counts_inc_normalised_atomic(
111111

112112
static void update_min_max(struct hdr_histogram* h, int64_t value)
113113
{
114-
h->min_value = (value < h->min_value && value != 0) ? value : h->min_value;
115-
h->max_value = (value > h->max_value) ? value : h->max_value;
114+
if (HDR_UNLIKELY(value > h->max_value))
115+
{
116+
h->max_value = value;
117+
}
118+
119+
if (HDR_UNLIKELY(value != 0 && value < h->min_value))
120+
{
121+
h->min_value = value;
122+
}
116123
}
117124

118125
static void update_min_max_atomic(struct hdr_histogram* h, int64_t value)

0 commit comments

Comments
 (0)