This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 634d967a0 [tablet] one less memory allocation in CBTree::count()
634d967a0 is described below

commit 634d967a0c620db2b3932c09b1fe13be1dc70f44
Author: Alexey Serbin <ale...@apache.org>
AuthorDate: Tue Apr 9 10:36:05 2024 -0700

    [tablet] one less memory allocation in CBTree::count()
    
    While reviewing [1], I noticed there is room for improvement in CBTree.
    One trivial one is avoiding calls to 'new' when an object might be
    allocated on the stack.  This makes sense since in some intensive Kudu
    workloads we might see significant lock contention in tcmalloc, and
    removing needless calls to 'new' helps to relieve that, even if it's
    not in the hot path.
    
    [1] https://gerrit.cloudera.org/#/c/21127/
    
    Change-Id: I01a68e0427b399db92b33c910185654d195150a5
    Reviewed-on: http://gerrit.cloudera.org:8080/21276
    Reviewed-by: Yingchun Lai <laiyingc...@apache.org>
    Reviewed-by: Yifan Zhang <chinazhangyi...@163.com>
    Tested-by: Alexey Serbin <ale...@apache.org>
---
 src/kudu/tablet/concurrent_btree.h | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/kudu/tablet/concurrent_btree.h 
b/src/kudu/tablet/concurrent_btree.h
index 2965c332f..85f38a690 100644
--- a/src/kudu/tablet/concurrent_btree.h
+++ b/src/kudu/tablet/concurrent_btree.h
@@ -1102,13 +1102,13 @@ class CBTree {
   // Note that this requires iterating through the entire tree,
   // so it is not very efficient.
   size_t count() const {
-    std::unique_ptr<CBTreeIterator<Traits>> iter(NewIterator());
+    CBTreeIterator<Traits> iter(this, frozen_);
     bool exact;
-    iter->SeekAtOrAfter(Slice(""), &exact);
+    iter.SeekAtOrAfter(Slice(""), &exact);
     size_t count = 0;
-    while (iter->IsValid()) {
-      count++;
-      iter->Next();
+    while (iter.IsValid()) {
+      ++count;
+      iter.Next();
     }
     return count;
   }
@@ -1855,11 +1855,11 @@ class CBTreeIterator {
     }
   }
 
-  const CBTree<Traits> *tree_;
+  const CBTree<Traits>* const tree_;
 
   // If true, the tree we are scanning is completely frozen and we don't
   // need to perform optimistic concurrency control or copies for safety.
-  bool tree_frozen_;
+  const bool tree_frozen_;
 
   bool seeked_;
   size_t idx_in_leaf_;

Reply via email to