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

apitrou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 967831b49d GH-40040: [C++][Gandiva] Make Gandiva's default cache size 
to be 5000 for object code cache (#40041)
967831b49d is described below

commit 967831b49d8ffeb9499c22aa3a812e46dc5cb1aa
Author: Yue <[email protected]>
AuthorDate: Wed Feb 14 16:40:56 2024 +0800

    GH-40040: [C++][Gandiva] Make Gandiva's default cache size to be 5000 for 
object code cache (#40041)
    
    ### Rationale for this change
    Gandiva's default cache is object code cache, however, the default cache 
size is still the old value for LLVM module based cache, which is too small.
    
    More details about the `GANDIVA_ENABLE_OBJECT_CODE_CACHE` flag can be found 
in GH-40040
    
    ### What changes are included in this PR?
    Remove the unused `GANDIVA_ENABLE_OBJECT_CODE_CACHE` flag and make the 
default cache size to be `500000` for object code cache.
    
    ### Are these changes tested?
    No
    
    ### Are there any user-facing changes?
    Yes, default cache size will be changed from 500 to 500000, and it may help 
the default deployment's performance.
    * Closes: #40040
    
    Authored-by: Yue Ni <[email protected]>
    Signed-off-by: Antoine Pitrou <[email protected]>
---
 cpp/src/gandiva/CMakeLists.txt |  1 +
 cpp/src/gandiva/cache.cc       |  6 +-----
 cpp/src/gandiva/cache_test.cc  | 42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/cpp/src/gandiva/CMakeLists.txt b/cpp/src/gandiva/CMakeLists.txt
index d773fb5ff5..9352ac5c4a 100644
--- a/cpp/src/gandiva/CMakeLists.txt
+++ b/cpp/src/gandiva/CMakeLists.txt
@@ -243,6 +243,7 @@ endfunction()
 add_gandiva_test(internals-test
                  SOURCES
                  bitmap_accumulator_test.cc
+                 cache_test.cc
                  engine_llvm_test.cc
                  function_registry_test.cc
                  function_signature_test.cc
diff --git a/cpp/src/gandiva/cache.cc b/cpp/src/gandiva/cache.cc
index f7e3e5e9f8..a1333ccdc5 100644
--- a/cpp/src/gandiva/cache.cc
+++ b/cpp/src/gandiva/cache.cc
@@ -23,11 +23,7 @@
 
 namespace gandiva {
 
-#ifdef GANDIVA_ENABLE_OBJECT_CODE_CACHE
-static const size_t DEFAULT_CACHE_SIZE = 500000;
-#else
-static const size_t DEFAULT_CACHE_SIZE = 500;
-#endif
+static const size_t DEFAULT_CACHE_SIZE = 5000;
 
 int GetCapacity() {
   size_t capacity = DEFAULT_CACHE_SIZE;
diff --git a/cpp/src/gandiva/cache_test.cc b/cpp/src/gandiva/cache_test.cc
new file mode 100644
index 0000000000..a146707079
--- /dev/null
+++ b/cpp/src/gandiva/cache_test.cc
@@ -0,0 +1,42 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "gandiva/cache.h"
+
+#include <gtest/gtest.h>
+
+namespace gandiva {
+class TestCacheKey {
+ public:
+  explicit TestCacheKey(int value) : value_(value) {}
+  std::size_t Hash() const { return value_; }
+  bool operator==(const TestCacheKey& other) const { return value_ == 
other.value_; }
+
+ private:
+  int value_;
+};
+
+TEST(TestCache, TestGetPut) {
+  Cache<TestCacheKey, std::string> cache(2);
+  cache.PutObjectCode(TestCacheKey(1), "hello");
+  cache.PutObjectCode(TestCacheKey(2), "world");
+  ASSERT_EQ(cache.GetObjectCode(TestCacheKey(1)), "hello");
+  ASSERT_EQ(cache.GetObjectCode(TestCacheKey(2)), "world");
+}
+
+TEST(TestCache, TestGetCacheCapacity) { ASSERT_EQ(GetCapacity(), 5000); }
+}  // namespace gandiva

Reply via email to