From 7f08a8503f56181c13d0a892dd11f0e31667c763 Mon Sep 17 00:00:00 2001 From: sdong Date: Fri, 1 Oct 2021 14:41:58 -0700 Subject: [PATCH] Remove IOSTATS_ADD_IF_POSITIVE() (#8984) Summary: IOSTATS_ADD_IF_POSITIVE() doesn't seem to a macro that aims to improve performance but does the opposite. The counter to add is almost always positive so the if is just a waste. Furthermore, adding to a thread local variable seemse to be much cheaper than an if condition if branch prediction has a possibility to be wrong. Remove the macro. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8984 Test Plan: See CI completes. Reviewed By: anand1976 Differential Revision: D31348163 fbshipit-source-id: 30af6d45e1aa8bbc09b2c046206cce6f67f4777a --- file/random_access_file_reader.cc | 4 ++-- monitoring/iostats_context_imp.h | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/file/random_access_file_reader.cc b/file/random_access_file_reader.cc index 489167719..6378155e3 100644 --- a/file/random_access_file_reader.cc +++ b/file/random_access_file_reader.cc @@ -181,7 +181,7 @@ IOStatus RandomAccessFileReader::Read(const IOOptions& opts, uint64_t offset, } *result = Slice(res_scratch, io_s.ok() ? pos : 0); } - IOSTATS_ADD_IF_POSITIVE(bytes_read, result->size()); + IOSTATS_ADD(bytes_read, result->size()); SetPerfLevel(prev_perf_level); } if (stats_ != nullptr && file_read_hist_ != nullptr) { @@ -346,7 +346,7 @@ IOStatus RandomAccessFileReader::MultiRead(const IOOptions& opts, start_ts, finish_ts, read_reqs[i].status); } #endif // ROCKSDB_LITE - IOSTATS_ADD_IF_POSITIVE(bytes_read, read_reqs[i].result.size()); + IOSTATS_ADD(bytes_read, read_reqs[i].result.size()); } SetPerfLevel(prev_perf_level); } diff --git a/monitoring/iostats_context_imp.h b/monitoring/iostats_context_imp.h index 69b0c6590..95e6ecc79 100644 --- a/monitoring/iostats_context_imp.h +++ b/monitoring/iostats_context_imp.h @@ -15,10 +15,6 @@ extern __thread IOStatsContext iostats_context; // increment a specific counter by the specified value #define IOSTATS_ADD(metric, value) (iostats_context.metric += value) -// Increase metric value only when it is positive -#define IOSTATS_ADD_IF_POSITIVE(metric, value) \ - if (value > 0) { IOSTATS_ADD(metric, value); } - // reset a specific counter to zero #define IOSTATS_RESET(metric) (iostats_context.metric = 0)