From d9bca1e14c80616f1f1df0f4def2062bf5841677 Mon Sep 17 00:00:00 2001 From: Islam AbdelRahman Date: Mon, 11 Jan 2016 16:48:15 -0800 Subject: [PATCH] Reduce iterator deletion overhead Summary: After introducing Iterator::PinData(), we have extra overhead of deleting the pinned iterators that we track in a std::set This patch avoid inserting to the std::set if we have only one iterator (normal use case when no iterators are pinned) Before this change ``` DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="newiterator" --db="/tmp/rocksdbtest-8616/dbbench" --use_existing_db --disable_auto_compactions newiterator : 1.006 micros/op 994013 ops/sec; newiterator : 0.994 micros/op 1006295 ops/sec; newiterator : 0.990 micros/op 1010422 ops/sec; ``` After change ``` DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="newiterator" --db="/tmp/rocksdbtest-8616/dbbench" --use_existing_db --disable_auto_compactions newiterator : 0.754 micros/op 1326588 ops/sec; newiterator : 0.759 micros/op 1317394 ops/sec; newiterator : 0.691 micros/op 1446704 ops/sec; ``` Test Plan: make check -j64 Reviewers: yhchiang, rven, anthony, sdong Reviewed By: sdong Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D52761 --- table/iterator_wrapper.h | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/table/iterator_wrapper.h b/table/iterator_wrapper.h index 1998c3740..eef300499 100644 --- a/table/iterator_wrapper.h +++ b/table/iterator_wrapper.h @@ -94,20 +94,9 @@ class IteratorWrapper { return iters_pinned_ && iter_->IsKeyPinned(); } - void DeletePinnedIterators(bool is_arena_mode) { - for (auto it : pinned_iters_) { - if (!is_arena_mode) { - delete it; - } else { - it->~InternalIterator(); - } - } - pinned_iters_.clear(); - } - void DeleteIter(bool is_arena_mode) { - if (iter_) { - pinned_iters_.insert(iter_); + if (iter_ && pinned_iters_.find(iter_) == pinned_iters_.end()) { + DestroyIterator(iter_, is_arena_mode); } DeletePinnedIterators(is_arena_mode); } @@ -132,6 +121,21 @@ class IteratorWrapper { } } + void DeletePinnedIterators(bool is_arena_mode) { + for (auto it : pinned_iters_) { + DestroyIterator(it, is_arena_mode); + } + pinned_iters_.clear(); + } + + inline void DestroyIterator(InternalIterator* it, bool is_arena_mode) { + if (!is_arena_mode) { + delete it; + } else { + it->~InternalIterator(); + } + } + InternalIterator* iter_; // If set to true, current and future iterators wont be deleted. bool iters_pinned_;