From 7013d10a9e8e1a183542111747dc9c324560975a Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 11 May 2010 18:17:02 -0700 Subject: [PATCH] Avoid unnecessary isalloc() calls. When heap profiling is enabled but deactivated, there is no need to call isalloc(ptr) in prof_{malloc,realloc}(). Avoid these calls, so that profiling overhead under such conditions is negligible. --- jemalloc/src/prof.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/jemalloc/src/prof.c b/jemalloc/src/prof.c index 93904b8c..88e8f44a 100644 --- a/jemalloc/src/prof.c +++ b/jemalloc/src/prof.c @@ -623,13 +623,8 @@ static inline void prof_sample_accum_update(size_t size) { - if (opt_lg_prof_sample == 0) { - /* - * Don't bother with sampling logic, since sampling interval is - * 1. - */ - return; - } + /* Sampling logic is unnecessary if the interval is 1. */ + assert(opt_lg_prof_sample != 0); /* Take care to avoid integer overflow. */ if (size >= prof_sample_threshold - prof_sample_accum) { @@ -647,11 +642,15 @@ prof_sample_accum_update(size_t size) void prof_malloc(const void *ptr, prof_thr_cnt_t *cnt) { - size_t size = isalloc(ptr); + size_t size; assert(ptr != NULL); - prof_sample_accum_update(size); + if (opt_lg_prof_sample != 0) { + size = isalloc(ptr); + prof_sample_accum_update(size); + } else if ((uintptr_t)cnt > (uintptr_t)1U) + size = isalloc(ptr); if ((uintptr_t)cnt > (uintptr_t)1U) { prof_ctx_set(ptr, cnt->ctx); @@ -679,11 +678,18 @@ void prof_realloc(const void *ptr, prof_thr_cnt_t *cnt, const void *old_ptr, size_t old_size, prof_ctx_t *old_ctx) { - size_t size = isalloc(ptr); + size_t size; prof_thr_cnt_t *told_cnt; - if (ptr != NULL) - prof_sample_accum_update(size); + assert(ptr != NULL || (uintptr_t)cnt <= (uintptr_t)1U); + + if (ptr != NULL) { + if (opt_lg_prof_sample != 0) { + size = isalloc(ptr); + prof_sample_accum_update(size); + } else if ((uintptr_t)cnt > (uintptr_t)1U) + size = isalloc(ptr); + } if ((uintptr_t)old_ctx > (uintptr_t)1U) { told_cnt = prof_lookup(old_ctx->bt);