Skip to content

Commit

Permalink
Introduce extra runtime parameter for lazy results
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTF committed Nov 24, 2024
1 parent 5f28e83 commit b969ccc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/engine/Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "engine/Operation.h"

#include "engine/QueryExecutionTree.h"
#include "global/RuntimeParameters.h"
#include "util/OnDestructionDontThrowDuringStackUnwinding.h"
#include "util/TransparentFunctors.h"

Expand Down Expand Up @@ -179,14 +180,13 @@ CacheValue Operation::runComputationAndPrepareForCache(
!unlikelyToFitInCache(cache.getMaxSizeSingleEntry())) {
AD_CONTRACT_CHECK(!pinned);
result.cacheDuringConsumption(
[maxSize = cache.getMaxSizeSingleEntry()](
const std::optional<Result::IdTableVocabPair>& currentIdTablePair,
const Result::IdTableVocabPair& newIdTable) {
[](const std::optional<Result::IdTableVocabPair>& currentIdTablePair,
const Result::IdTableVocabPair& newIdTable) {
auto currentSize =
currentIdTablePair.has_value()
? CacheValue::getSize(currentIdTablePair.value().idTable_)
: 0_B;
return maxSize >=
return RuntimeParameters().get<"lazy-result-max-cache-size">() >=
currentSize + CacheValue::getSize(newIdTable.idTable_);
},
[runtimeInfo = getRuntimeInfoPointer(), &cache,
Expand Down
3 changes: 2 additions & 1 deletion src/global/RuntimeParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ inline auto& RuntimeParameters() {
Bool<"group-by-disable-index-scan-optimizations">{false},
SizeT<"service-max-value-rows">{10'000},
SizeT<"query-planning-budget">{1500},
Bool<"throw-on-unbound-variables">{false}};
Bool<"throw-on-unbound-variables">{false},
MemorySizeParameter<"lazy-result-max-cache-size">{500_MB}};
}();
return params;
}
Expand Down
7 changes: 4 additions & 3 deletions test/OperationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "engine/NeutralElementOperation.h"
#include "engine/ValuesForTesting.h"
#include "global/RuntimeParameters.h"
#include "util/IdTableHelpers.h"
#include "util/IndexTestHelpers.h"
#include "util/OperationTestHelpers.h"
Expand Down Expand Up @@ -582,21 +583,21 @@ TEST(Operation, checkLazyOperationIsNotCachedIfTooLarge) {

ad_utility::Timer timer{ad_utility::Timer::InitialStatus::Started};

auto originalSize = qec->getQueryTreeCache().getMaxSizeSingleEntry();
auto originalSize = RuntimeParameters().get<"lazy-result-max-cache-size">();

// Too small for storage
qec->getQueryTreeCache().setMaxSizeSingleEntry(1_B);
RuntimeParameters().set<"lazy-result-max-cache-size">(1_B);

auto cacheValue = valuesForTesting.runComputationAndPrepareForCache(
timer, ComputationMode::LAZY_IF_SUPPORTED, "test", false);
EXPECT_FALSE(qec->getQueryTreeCache().cacheContains("test"));
qec->getQueryTreeCache().setMaxSizeSingleEntry(originalSize);

for ([[maybe_unused]] Result::IdTableVocabPair& _ :
cacheValue.resultTable().idTables()) {
}

EXPECT_FALSE(qec->getQueryTreeCache().cacheContains("test"));
RuntimeParameters().set<"lazy-result-max-cache-size">(originalSize);
}

// _____________________________________________________________________________
Expand Down

0 comments on commit b969ccc

Please sign in to comment.