Skip to content

Commit

Permalink
Optimize headers even more (#1785)
Browse files Browse the repository at this point in the history
Follow-up to #1781, eliminates some dead code and optimizes includes again by moving the very expensive include of `RuntimeParameters.h` into the cpp files.
  • Loading branch information
RobinTF authored Feb 12, 2025
1 parent 2fad765 commit eef2765
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 210 deletions.
3 changes: 2 additions & 1 deletion src/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ add_library(engine
CartesianProductJoin.cpp TextIndexScanForWord.cpp TextIndexScanForEntity.cpp
TextLimit.cpp LazyGroupBy.cpp GroupByHashMapOptimization.cpp SpatialJoin.cpp
CountConnectedSubgraphs.cpp SpatialJoinAlgorithms.cpp PathSearch.cpp ExecuteUpdate.cpp
Describe.cpp GraphStoreProtocol.cpp)
Describe.cpp GraphStoreProtocol.cpp
QueryExecutionContext.cpp)
qlever_target_link_libraries(engine util index parser sparqlExpressions http SortPerformanceEstimator Boost::iostreams s2)
10 changes: 2 additions & 8 deletions src/engine/OptionalJoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,8 @@ class OptionalJoin : public Operation {
return {_left.get(), _right.get()};
}

/**
* @brief Joins two result tables on any number of columns, inserting the
* special value ID_NO_VALUE for any entries marked as optional.
* @param a
* @param b
* @param joinColumns
* @param result
*/
// Joins two result tables on any number of columns, inserting the special
// value `Id::makeUndefined()` for any entries marked as optional.
void optionalJoin(
const IdTable& left, const IdTable& right,
const std::vector<std::array<ColumnIndex, 2>>& joinColumns,
Expand Down
11 changes: 11 additions & 0 deletions src/engine/QueryExecutionContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2025, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Robin Textor-Falconi <textorr@informatik.uni-freiburg.de>

#include "engine/QueryExecutionContext.h"

#include "global/RuntimeParameters.h"

bool QueryExecutionContext::areWebSocketUpdatesEnabled() {
return RuntimeParameters().get<"websocket-updates-enabled">();
}
9 changes: 4 additions & 5 deletions src/engine/QueryExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#pragma once

#include <global/RuntimeParameters.h>

#include <memory>
#include <string>

Expand All @@ -19,7 +17,6 @@
#include "index/Index.h"
#include "util/Cache.h"
#include "util/ConcurrentCache.h"
#include "util/Synchronized.h"

// The value of the `QueryResultCache` below. It consists of a `Result` together
// with its `RuntimeInfo`.
Expand Down Expand Up @@ -151,6 +148,9 @@ class QueryExecutionContext {
return areWebsocketUpdatesEnabled_;
}

private:
static bool areWebSocketUpdatesEnabled();

private:
const Index& _index;

Expand All @@ -168,6 +168,5 @@ class QueryExecutionContext {
std::function<void(std::string)> updateCallback_;
// Cache the state of that runtime parameter to reduce the contention of the
// mutex.
bool areWebsocketUpdatesEnabled_ =
RuntimeParameters().get<"websocket-updates-enabled">();
bool areWebsocketUpdatesEnabled_ = areWebSocketUpdatesEnabled();
};
2 changes: 1 addition & 1 deletion src/engine/QueryExecutionTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <vector>

#include "engine/Sort.h"
#include "parser/RdfEscaping.h"
#include "global/RuntimeParameters.h"

using std::string;

Expand Down
95 changes: 1 addition & 94 deletions src/global/Id.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
// Author: Björn Buchhold (buchhold@informatik.uni-freiburg.de)
#pragma once

#include <absl/strings/str_cat.h>

#include <cstdint>
#include <limits>

#include "global/ValueId.h"
#include "util/Exception.h"

using Id = ValueId;
typedef uint16_t Score;
using Score = uint16_t;

// TODO<joka921> Make the following ID and index types strong.
using ColumnIndex = uint64_t;
Expand All @@ -23,92 +19,3 @@ using WordIndex = uint64_t;
using WordOrEntityIndex = uint64_t;
using TextBlockIndex = uint64_t;
using CompressionCode = uint64_t;

// Integers, that are probably not integers but strong IDs or indices, but their
// true nature is still to be discovered.
using UnknownIndex = uint64_t;

// A value to use when the result should be empty (e.g. due to an optional join)
// The highest two values are used as sentinels.
static const Id ID_NO_VALUE = Id::makeUndefined();

namespace ad_utility {

// An exception that is thrown when an integer overflow occurs in the
// `MilestoneIdManager`
class MilestoneIdOverflowException : public std::exception {
private:
std::string _message;

public:
explicit MilestoneIdOverflowException(std::string message)
: _message{std::move(message)} {}
[[nodiscard]] const char* what() const noexcept override {
return _message.c_str();
}
};

// Manages two kinds of IDs: plain IDs (unsigned 64-bit integers, just called
// "IDs" in the following), and milestone IDs (unsigned 64-bit integers that are
// multiples of `distanceBetweenMilestones`. This class has the functionality to
// find the next milestone of plain ID, to check whether an ID is amilestone ID
// and to convert milestone IDs from and to a local ID space.
template <size_t distanceBetweenMilestones>
class MilestoneIdManager {
private:
// The next free ID;
uint64_t _nextId{0};
// The last ID that was assigned. Used for overflow detection.
uint64_t _previousId{0};

public:
MilestoneIdManager() = default;

// The maximum number of milestone Ids.
constexpr static uint64_t numMilestoneIds =
std::numeric_limits<uint64_t>::max() / distanceBetweenMilestones;

// Get the smallest milestone ID that is larger than all (milestone and
// non-milestone) previously obtained IDs.
uint64_t getNextMilestoneId() {
if (!isMilestoneId(_nextId)) {
_nextId = (milestoneIdFromLocal(milestoneIdToLocal(_nextId) + 1));
}
return getNextId();
}

// Get the smallest ID that is larger than all previously obtained IDs.
uint64_t getNextId() {
if (_nextId < _previousId) {
throw MilestoneIdOverflowException{absl::StrCat(
"Overflow while assigning Ids from a MilestoneIdManager. The "
"previous "
"milestone Id was ",
_previousId, " the next id would be ", _nextId,
". The maximum number of milestones is ", numMilestoneIds, ".")};
}
_previousId = _nextId;
_nextId++;
return _previousId;
}

// Is this ID a milestone id, equivalently: Is this ID a multiple of
// `distanceBetweenMilestones`?
constexpr static bool isMilestoneId(uint64_t id) {
return id % distanceBetweenMilestones == 0;
}

// Convert a milestone ID to its "local" ID by dividing it by
// `distanceBetweenMilestones` (the i-th milestone ID will become `i`).
constexpr static uint64_t milestoneIdToLocal(uint64_t id) {
return id / distanceBetweenMilestones;
}

// Convert "local" ID to milestone ID by multiplying it with
// `distanceBetweenMilestones`.
constexpr static uint64_t milestoneIdFromLocal(uint64_t id) {
return id * distanceBetweenMilestones;
}
};

} // namespace ad_utility
4 changes: 2 additions & 2 deletions src/index/VocabularyMerger.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ struct VocabularyMetaData {
bool contains(Id id) const { return begin_ <= id && id < end_; }

private:
Id begin_ = ID_NO_VALUE;
Id end_ = ID_NO_VALUE;
Id begin_ = Id::makeUndefined();
Id end_ = Id::makeUndefined();
std::string prefix_;
bool beginWasSeen_ = false;
};
Expand Down
1 change: 0 additions & 1 deletion src/util/AllocatorWithLimit.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <absl/strings/str_cat.h>

#include <atomic>
#include <functional>
#include <memory>

Expand Down
2 changes: 0 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ addLinkAndDiscoverTest(ContentEncodingHelperTest http)

addLinkAndDiscoverTest(PrefixCompressorTest)

addLinkAndDiscoverTest(MilestoneIdTest)

addLinkAndDiscoverTest(VocabularyTest index)

addLinkAndDiscoverTestNoLibs(IteratorTest)
Expand Down
12 changes: 6 additions & 6 deletions test/GroupByTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ TEST_F(GroupByTest, doGroupBy) {
ASSERT_EQ(123u, outTable._data[1][9]);
ASSERT_EQ(0u, outTable._data[2][9]);
ASSERT_EQ(ID_NO_VALUE, outTable._data[0][10]);
ASSERT_EQ(ID_NO_VALUE, outTable._data[1][10]);
ASSERT_EQ(ID_NO_VALUE, outTable._data[2][10]);
ASSERT_EQ(Id::makeUndefined(), outTable._data[0][10]);
ASSERT_EQ(Id::makeUndefined(), outTable._data[1][10]);
ASSERT_EQ(Id::makeUndefined(), outTable._data[2][10]);
std::memcpy(&buffer, &outTable._data[0][11], sizeof(float));
ASSERT_FLOAT_EQ(-3, buffer);
Expand All @@ -283,9 +283,9 @@ TEST_F(GroupByTest, doGroupBy) {
ASSERT_EQ(41223u, outTable._data[1][13]);
ASSERT_EQ(41223u, outTable._data[2][13]);
ASSERT_EQ(ID_NO_VALUE, outTable._data[0][14]);
ASSERT_EQ(ID_NO_VALUE, outTable._data[1][14]);
ASSERT_EQ(ID_NO_VALUE, outTable._data[2][14]);
ASSERT_EQ(Id::makeUndefined(), outTable._data[0][14]);
ASSERT_EQ(Id::makeUndefined(), outTable._data[1][14]);
ASSERT_EQ(Id::makeUndefined(), outTable._data[2][14]);
std::memcpy(&buffer, &outTable._data[0][15], sizeof(float));
ASSERT_FLOAT_EQ(2, buffer);
Expand Down
90 changes: 0 additions & 90 deletions test/MilestoneIdTest.cpp

This file was deleted.

0 comments on commit eef2765

Please sign in to comment.