From 747f8a8ecd2513c43b605591147f68b52b5276d1 Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Tue, 12 Aug 2014 23:00:02 -0700 Subject: [PATCH] Small memory footprint reduction for folly::MultiLevelTimeSeries Summary: * Spend some extra time in getNumBuckets() in order to save space: 8 bytes per object on 64-bit platforms. Test Plan: Ran the unit tests Reviewed By: simpkins@fb.com Subscribers: ruibalp FB internal diff: D1488345 --- folly/stats/MultiLevelTimeSeries-defs.h | 3 +-- folly/stats/MultiLevelTimeSeries.h | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/folly/stats/MultiLevelTimeSeries-defs.h b/folly/stats/MultiLevelTimeSeries-defs.h index 6c6de184..028f764d 100644 --- a/folly/stats/MultiLevelTimeSeries-defs.h +++ b/folly/stats/MultiLevelTimeSeries-defs.h @@ -26,8 +26,7 @@ MultiLevelTimeSeries::MultiLevelTimeSeries( size_t numBuckets, size_t numLevels, const TimeType levelDurations[]) - : numBuckets_(numBuckets), - cachedTime_(0), + : cachedTime_(0), cachedSum_(0), cachedCount_(0) { CHECK_GT(numLevels, 0); diff --git a/folly/stats/MultiLevelTimeSeries.h b/folly/stats/MultiLevelTimeSeries.h index 7a81046e..84c05380 100644 --- a/folly/stats/MultiLevelTimeSeries.h +++ b/folly/stats/MultiLevelTimeSeries.h @@ -73,7 +73,10 @@ class MultiLevelTimeSeries { /* * Return the number of buckets used to track time series at each level. */ - size_t numBuckets() const { return numBuckets_; } + size_t numBuckets() const { + // The constructor ensures that levels_ has at least one item + return levels_[0].numBuckets(); + } /* * Return the number of levels tracked by MultiLevelTimeSeries. @@ -297,7 +300,6 @@ class MultiLevelTimeSeries { void flush(); private: - size_t numBuckets_; std::vector levels_; // Updates within the same time interval are cached -- 2.34.1