From: Brian Pane Date: Wed, 13 Aug 2014 06:00:02 +0000 (-0700) Subject: Small memory footprint reduction for folly::MultiLevelTimeSeries X-Git-Tag: v0.22.0~409 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=747f8a8ecd2513c43b605591147f68b52b5276d1;p=folly.git 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 --- 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