Skip to content

Commit 967831b

Browse files
authored
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 <niyue.com@gmail.com> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent 0dbbd43 commit 967831b

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

cpp/src/gandiva/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ endfunction()
243243
add_gandiva_test(internals-test
244244
SOURCES
245245
bitmap_accumulator_test.cc
246+
cache_test.cc
246247
engine_llvm_test.cc
247248
function_registry_test.cc
248249
function_signature_test.cc

cpp/src/gandiva/cache.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323

2424
namespace gandiva {
2525

26-
#ifdef GANDIVA_ENABLE_OBJECT_CODE_CACHE
27-
static const size_t DEFAULT_CACHE_SIZE = 500000;
28-
#else
29-
static const size_t DEFAULT_CACHE_SIZE = 500;
30-
#endif
26+
static const size_t DEFAULT_CACHE_SIZE = 5000;
3127

3228
int GetCapacity() {
3329
size_t capacity = DEFAULT_CACHE_SIZE;

cpp/src/gandiva/cache_test.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#include "gandiva/cache.h"
19+
20+
#include <gtest/gtest.h>
21+
22+
namespace gandiva {
23+
class TestCacheKey {
24+
public:
25+
explicit TestCacheKey(int value) : value_(value) {}
26+
std::size_t Hash() const { return value_; }
27+
bool operator==(const TestCacheKey& other) const { return value_ == other.value_; }
28+
29+
private:
30+
int value_;
31+
};
32+
33+
TEST(TestCache, TestGetPut) {
34+
Cache<TestCacheKey, std::string> cache(2);
35+
cache.PutObjectCode(TestCacheKey(1), "hello");
36+
cache.PutObjectCode(TestCacheKey(2), "world");
37+
ASSERT_EQ(cache.GetObjectCode(TestCacheKey(1)), "hello");
38+
ASSERT_EQ(cache.GetObjectCode(TestCacheKey(2)), "world");
39+
}
40+
41+
TEST(TestCache, TestGetCacheCapacity) { ASSERT_EQ(GetCapacity(), 5000); }
42+
} // namespace gandiva

0 commit comments

Comments
 (0)