Skip to content

Commit

Permalink
Replace arangodb::containers::SmallVector with std::span and absl::In…
Browse files Browse the repository at this point in the history
…linedVector (arangodb#16216)

* Replace arangodb::containers::SmallVector with std::span and absl::InlinedVector

* Use boost::container::small_vector instead of absl::InlinedVector
Also make common using declaration for it

* Remove unnecessary vector<bool>

* Fix by review

* Remove unnecessary vector<bool>

* Fix
  • Loading branch information
MBkkt authored May 10, 2022
1 parent 4545d31 commit 33c30ec
Show file tree
Hide file tree
Showing 70 changed files with 959 additions and 1,640 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,6 @@ link_libraries(
absl::flat_hash_map
absl::node_hash_set
absl::node_hash_map
absl::inlined_vector
absl::synchronization
)

Expand Down
7 changes: 2 additions & 5 deletions arangod/Aql/AqlItemBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,7 @@ SharedAqlItemBlockPtr AqlItemBlock::slice(size_t from, size_t to) const {
TRI_ASSERT(from < to);
TRI_ASSERT(to <= _numRows);

arangodb::containers::SmallVector<
std::pair<size_t, size_t>>::allocator_type::arena_type arena;
arangodb::containers::SmallVector<std::pair<size_t, size_t>> ranges{arena};
containers::SmallVector<std::pair<size_t, size_t>, 4> ranges;
ranges.emplace_back(from, to);
return slice(ranges);
}
Expand All @@ -580,8 +578,7 @@ SharedAqlItemBlockPtr AqlItemBlock::slice(size_t from, size_t to) const {
* @return SharedAqlItemBlockPtr A block where all the slices are contained in
* the order of the list
*/
auto AqlItemBlock::slice(
arangodb::containers::SmallVector<std::pair<size_t, size_t>> const& ranges)
auto AqlItemBlock::slice(std::span<std::pair<size_t, size_t> const> ranges)
const -> SharedAqlItemBlockPtr {
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
// Analyze correctness of ranges
Expand Down
6 changes: 4 additions & 2 deletions arangod/Aql/AqlItemBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
#include "Aql/AqlValue.h"
#include "Basics/ResourceUsage.h"
#include "Containers/FlatHashMap.h"

#include "Containers/SmallVector.h"

#include <limits>
#include <span>
#include <thread>
#include <unordered_map>
#include <unordered_set>
Expand Down Expand Up @@ -255,8 +257,8 @@ class AqlItemBlock {
* @return SharedAqlItemBlockPtr A block where all the slices are contained in
* the order of the list
*/
auto slice(arangodb::containers::SmallVector<std::pair<size_t, size_t>> const&
ranges) const -> SharedAqlItemBlockPtr;
auto slice(std::span<std::pair<size_t, size_t> const> ranges) const
-> SharedAqlItemBlockPtr;

/// @brief create an AqlItemBlock with a single row, with copies of the
/// specified registers from the current block
Expand Down
4 changes: 2 additions & 2 deletions arangod/Aql/Ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3005,7 +3005,7 @@ AstNode* Ast::makeConditionFromExample(AstNode const* node) {
}

AstNode* result = nullptr;
::arangodb::containers::SmallVectorWithArena<std::string_view> attributeParts;
containers::SmallVector<std::string_view, 4> attributeParts;

std::function<void(AstNode const*)> createCondition =
[&](AstNode const* object) -> void {
Expand Down Expand Up @@ -3914,7 +3914,7 @@ AstNode const* Ast::resolveConstAttributeAccess(AstNode const* node,
TRI_ASSERT(node->type == NODE_TYPE_ATTRIBUTE_ACCESS);
AstNode const* original = node;

::arangodb::containers::SmallVectorWithArena<std::string_view> attributeNames;
containers::SmallVector<std::string_view, 4> attributeNames;

while (node->type == NODE_TYPE_ATTRIBUTE_ACCESS) {
attributeNames.push_back(node->getStringView());
Expand Down
2 changes: 1 addition & 1 deletion arangod/Aql/CalculationNodeVarFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace aql {

CalculationNodeVarFinder::CalculationNodeVarFinder(
Variable const* lookingFor,
::arangodb::containers::SmallVector<ExecutionNode*>& out) noexcept
containers::SmallVector<ExecutionNode*, 8>& out) noexcept
: _lookingFor(lookingFor), _out(out) {}

bool CalculationNodeVarFinder::before(ExecutionNode* en) {
Expand Down
4 changes: 2 additions & 2 deletions arangod/Aql/CalculationNodeVarFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class CalculationNodeVarFinder final
: public WalkerWorker<ExecutionNode, WalkerUniqueness::NonUnique> {
Variable const* _lookingFor;

::arangodb::containers::SmallVector<ExecutionNode*>& _out;
containers::SmallVector<ExecutionNode*, 8>& _out;

VarSet _currentUsedVars;

public:
CalculationNodeVarFinder(
Variable const* var,
::arangodb::containers::SmallVector<ExecutionNode*>& out) noexcept;
containers::SmallVector<ExecutionNode*, 8>& out) noexcept;

bool before(ExecutionNode*) override final;
};
Expand Down
9 changes: 2 additions & 7 deletions arangod/Aql/ConstFetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "Aql/SkipResult.h"
#include "Basics/Exceptions.h"
#include "Basics/voc-errors.h"
#include "Containers/SmallVector.h"

#include <algorithm>

Expand All @@ -55,10 +54,7 @@ auto ConstFetcher::execute(AqlCallStack& stack)
AqlItemBlockInputRange{MainQueryState::DONE}};
}

arangodb::containers::SmallVector<
std::pair<size_t, size_t>>::allocator_type::arena_type arena;
arangodb::containers::SmallVector<std::pair<size_t, size_t>> sliceIndexes{
arena};
containers::SmallVector<std::pair<size_t, size_t>, 4> sliceIndexes;

sliceIndexes.emplace_back(_rowIndex, _blockForPassThrough->numRows());

Expand Down Expand Up @@ -238,8 +234,7 @@ auto ConstFetcher::numRowsLeft() const noexcept -> size_t {
}

auto ConstFetcher::canUseFullBlock(
arangodb::containers::SmallVector<std::pair<size_t, size_t>> const& ranges)
const noexcept -> bool {
std::span<std::pair<size_t, size_t> const> ranges) const noexcept -> bool {
TRI_ASSERT(!ranges.empty());
if (ranges.front().first != 0) {
// We do not start at the first index.
Expand Down
5 changes: 2 additions & 3 deletions arangod/Aql/ConstFetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#include "Aql/ExecutionState.h"
#include "Aql/InputAqlItemRow.h"
#include "Aql/SkipResult.h"
#include "Containers/SmallVector.h"

#include <memory>
#include <span>

namespace arangodb {
namespace aql {
Expand Down Expand Up @@ -106,8 +106,7 @@ class ConstFetcher {
auto indexIsValid() const noexcept -> bool;
auto numRowsLeft() const noexcept -> size_t;
auto canUseFullBlock(
arangodb::containers::SmallVector<std::pair<size_t, size_t>> const&
ranges) const noexcept -> bool;
std::span<std::pair<size_t, size_t> const> ranges) const noexcept -> bool;
};

} // namespace aql
Expand Down
10 changes: 3 additions & 7 deletions arangod/Aql/ExecutionNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,11 +718,7 @@ bool ExecutionNode::doWalk(WalkerWorkerBase<ExecutionNode>& worker,
// we can be quite generous with the buffer size since the implementation is
// not recursive.
constexpr std::size_t NumBufferedEntries = 1000;
constexpr std::size_t BufferSize = sizeof(Entry) * NumBufferedEntries;
containers::SmallVectorWithArena<Entry, BufferSize> nodes;
// Our stackbased arena can hold NumBufferedEntries, so we reserve everythhing
// at once.
nodes.reserve(NumBufferedEntries);
containers::SmallVector<Entry, NumBufferedEntries> nodes;
nodes.emplace_back(const_cast<ExecutionNode*>(this), State::Pending);

auto enqueDependencies = [&nodes](std::vector<ExecutionNode*>& deps) {
Expand Down Expand Up @@ -2205,11 +2201,11 @@ bool SubqueryNode::mayAccessCollections() {
ExecutionNode::SHORTEST_PATH,
ExecutionNode::K_SHORTEST_PATHS};

::arangodb::containers::SmallVectorWithArena<ExecutionNode*> nodes;
containers::SmallVector<ExecutionNode*, 8> nodes;

NodeFinder<std::initializer_list<ExecutionNode::NodeType>,
WalkerUniqueness::Unique>
finder(types, nodes.vector(), true);
finder(types, nodes, true);
_subquery->walk(finder);

if (!nodes.empty()) {
Expand Down
14 changes: 6 additions & 8 deletions arangod/Aql/ExecutionPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,7 @@ ExecutionNode* ExecutionPlan::fromNode(AstNode const* node) {
template<WalkerUniqueness U>
/// @brief find nodes of certain types
void ExecutionPlan::findNodesOfType(
::arangodb::containers::SmallVector<ExecutionNode*>& result,
containers::SmallVector<ExecutionNode*, 8>& result,
std::initializer_list<ExecutionNode::NodeType> const& types,
bool enterSubqueries) {
// check if any of the node types is actually present in the plan
Expand All @@ -2353,30 +2353,30 @@ void ExecutionPlan::findNodesOfType(

/// @brief find nodes of a certain type
void ExecutionPlan::findNodesOfType(
::arangodb::containers::SmallVector<ExecutionNode*>& result,
containers::SmallVector<ExecutionNode*, 8>& result,
ExecutionNode::NodeType type, bool enterSubqueries) {
findNodesOfType<WalkerUniqueness::NonUnique>(result, {type}, enterSubqueries);
}

/// @brief find nodes of certain types
void ExecutionPlan::findNodesOfType(
::arangodb::containers::SmallVector<ExecutionNode*>& result,
containers::SmallVector<ExecutionNode*, 8>& result,
std::initializer_list<ExecutionNode::NodeType> const& types,
bool enterSubqueries) {
findNodesOfType<WalkerUniqueness::NonUnique>(result, types, enterSubqueries);
}

/// @brief find nodes of certain types
void ExecutionPlan::findUniqueNodesOfType(
::arangodb::containers::SmallVector<ExecutionNode*>& result,
containers::SmallVector<ExecutionNode*, 8>& result,
std::initializer_list<ExecutionNode::NodeType> const& types,
bool enterSubqueries) {
findNodesOfType<WalkerUniqueness::Unique>(result, types, enterSubqueries);
}

/// @brief find all end nodes in a plan
void ExecutionPlan::findEndNodes(
::arangodb::containers::SmallVector<ExecutionNode*>& result,
containers::SmallVector<ExecutionNode*, 8>& result,
bool enterSubqueries) const {
EndNodeFinder finder(result, enterSubqueries);
root()->walk(finder);
Expand Down Expand Up @@ -2678,9 +2678,7 @@ void ExecutionPlan::findCollectionAccessVariables() {
}

void ExecutionPlan::prepareTraversalOptions() {
::arangodb::containers::SmallVector<
ExecutionNode*>::allocator_type::arena_type a;
::arangodb::containers::SmallVector<ExecutionNode*> nodes{a};
containers::SmallVector<ExecutionNode*, 8> nodes;
findNodesOfType(nodes,
{arangodb::aql::ExecutionNode::TRAVERSAL,
arangodb::aql::ExecutionNode::SHORTEST_PATH,
Expand Down
23 changes: 10 additions & 13 deletions arangod/Aql/ExecutionPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,22 @@ class ExecutionPlan {
}

/// @brief find nodes of a certain type
void findNodesOfType(
::arangodb::containers::SmallVector<ExecutionNode*>& result,
ExecutionNode::NodeType, bool enterSubqueries);
void findNodesOfType(containers::SmallVector<ExecutionNode*, 8>& result,
ExecutionNode::NodeType, bool enterSubqueries);

/// @brief find nodes of certain types
void findNodesOfType(
::arangodb::containers::SmallVector<ExecutionNode*>& result,
std::initializer_list<ExecutionNode::NodeType> const&,
bool enterSubqueries);
void findNodesOfType(containers::SmallVector<ExecutionNode*, 8>& result,
std::initializer_list<ExecutionNode::NodeType> const&,
bool enterSubqueries);

/// @brief find unique nodes of certain types
void findUniqueNodesOfType(
::arangodb::containers::SmallVector<ExecutionNode*>& result,
containers::SmallVector<ExecutionNode*, 8>& result,
std::initializer_list<ExecutionNode::NodeType> const&,
bool enterSubqueries);

/// @brief find all end nodes in a plan
void findEndNodes(::arangodb::containers::SmallVector<ExecutionNode*>& result,
void findEndNodes(containers::SmallVector<ExecutionNode*, 8>& result,
bool enterSubqueries) const;

/// @brief determine and set _varsUsedLater and _varSetBy
Expand Down Expand Up @@ -319,10 +317,9 @@ class ExecutionPlan {
private:
template<WalkerUniqueness U>
/// @brief find nodes of certain types
void findNodesOfType(
::arangodb::containers::SmallVector<ExecutionNode*>& result,
std::initializer_list<ExecutionNode::NodeType> const&,
bool enterSubqueries);
void findNodesOfType(containers::SmallVector<ExecutionNode*, 8>& result,
std::initializer_list<ExecutionNode::NodeType> const&,
bool enterSubqueries);

/// @brief creates a calculation node
ExecutionNode* createCalculation(Variable*, AstNode const*, ExecutionNode*);
Expand Down
6 changes: 3 additions & 3 deletions arangod/Aql/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,10 +825,10 @@ AqlValue Expression::executeSimpleExpressionFCallCxx(ExpressionContext& ctx,
// use stack-based allocation for the first few function call
// parameters. this saves a few heap allocations per function
// call invocation
::arangodb::containers::SmallVectorWithArena<AqlValue> parameters;
containers::SmallVector<AqlValue, 8> parameters;

// same here
::arangodb::containers::SmallVectorWithArena<uint64_t> destroyParameters;
containers::SmallVector<uint64_t, 8> destroyParameters;

explicit FunctionParameters(size_t n) {
parameters.reserve(n);
Expand Down Expand Up @@ -866,7 +866,7 @@ AqlValue Expression::executeSimpleExpressionFCallCxx(ExpressionContext& ctx,
TRI_ASSERT(params.parameters.size() == params.destroyParameters.size());
TRI_ASSERT(params.parameters.size() == n);

AqlValue a = func->implementation(&ctx, *node, params.parameters.vector());
AqlValue a = func->implementation(&ctx, *node, params.parameters);
mustDestroy = true; // function result is always dynamic

return a;
Expand Down
Loading

0 comments on commit 33c30ec

Please sign in to comment.