Use MemoryResource for members of ExpandVariableCursor
Summary: Unfortunately, the written micro benchmark only reports minor improvements compared to default allocator. The results are in some cases even a tiny bit worse. Reviewers: mtomic, mferencevic, llugovic Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2039
This commit is contained in:
parent
b09b21b832
commit
801bdb3a91
@ -689,7 +689,10 @@ class ExpandVariableCursor : public Cursor {
|
||||
ExpandVariableCursor(const ExpandVariable &self,
|
||||
database::GraphDbAccessor *db,
|
||||
utils::MemoryResource *mem)
|
||||
: self_(self), input_cursor_(self.input_->MakeCursor(db, mem)) {}
|
||||
: self_(self),
|
||||
input_cursor_(self.input_->MakeCursor(db, mem)),
|
||||
edges_(mem),
|
||||
edges_it_(mem) {}
|
||||
|
||||
bool Pull(Frame &frame, ExecutionContext &context) override {
|
||||
SCOPED_PROFILE_OP("ExpandVariable");
|
||||
@ -741,14 +744,15 @@ class ExpandVariableCursor : public Cursor {
|
||||
|
||||
// a stack of edge iterables corresponding to the level/depth of
|
||||
// the expansion currently being Pulled
|
||||
std::vector<decltype(ExpandFromVertex(std::declval<VertexAccessor>(),
|
||||
EdgeAtom::Direction::IN,
|
||||
self_.common_.edge_types))>
|
||||
edges_;
|
||||
using ExpandEdges = decltype(ExpandFromVertex(std::declval<VertexAccessor>(),
|
||||
EdgeAtom::Direction::IN,
|
||||
self_.common_.edge_types));
|
||||
std::vector<ExpandEdges, utils::Allocator<ExpandEdges>> edges_;
|
||||
|
||||
// an iterator indicating the possition in the corresponding edges_
|
||||
// element
|
||||
std::vector<decltype(edges_.begin()->begin())> edges_it_;
|
||||
// an iterator indicating the position in the corresponding edges_ element
|
||||
std::vector<decltype(edges_.begin()->begin()),
|
||||
utils::Allocator<decltype(edges_.begin()->begin())>>
|
||||
edges_it_;
|
||||
|
||||
/**
|
||||
* Helper function that Pulls from the input vertex and
|
||||
|
@ -17,6 +17,23 @@ static void AddVertices(database::GraphDb *db, int vertex_count) {
|
||||
dba.Commit();
|
||||
}
|
||||
|
||||
static const char *kStartLabel = "start";
|
||||
|
||||
static void AddStarGraph(database::GraphDb *db, int spoke_count, int depth) {
|
||||
auto dba = db->Access();
|
||||
VertexAccessor center_vertex = dba.InsertVertex();
|
||||
center_vertex.add_label(dba.Label(kStartLabel));
|
||||
for (int i = 0; i < spoke_count; ++i) {
|
||||
VertexAccessor prev_vertex = center_vertex;
|
||||
for (int j = 0; j < depth; ++j) {
|
||||
auto dest = dba.InsertVertex();
|
||||
dba.InsertEdge(prev_vertex, dest, dba.EdgeType("Type"));
|
||||
prev_vertex = dest;
|
||||
}
|
||||
}
|
||||
dba.Commit();
|
||||
}
|
||||
|
||||
static query::CypherQuery *ParseCypherQuery(const std::string &query_string,
|
||||
query::AstStorage *ast) {
|
||||
query::frontend::ParsingContext parsing_context;
|
||||
@ -69,8 +86,8 @@ static void DistinctLinearAllocator(benchmark::State &state) {
|
||||
query::AstStorage ast;
|
||||
query::Parameters parameters;
|
||||
database::GraphDb db;
|
||||
auto dba = db.Access();
|
||||
AddVertices(&db, state.range(0));
|
||||
auto dba = db.Access();
|
||||
auto query_string = "MATCH (s) RETURN DISTINCT s";
|
||||
auto *cypher_query = ParseCypherQuery(query_string, &ast);
|
||||
auto symbol_table = query::MakeSymbolTable(cypher_query);
|
||||
@ -97,4 +114,89 @@ BENCHMARK(DistinctLinearAllocator)
|
||||
->Range(1024, 1U << 21U)
|
||||
->Unit(benchmark::kMicrosecond);
|
||||
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
static void ExpandVariableDefaultAllocator(benchmark::State &state) {
|
||||
query::AstStorage ast;
|
||||
query::Parameters parameters;
|
||||
database::GraphDb db;
|
||||
AddStarGraph(&db, state.range(0), state.range(1));
|
||||
query::SymbolTable symbol_table;
|
||||
auto input_symbol = symbol_table.CreateSymbol("input", false);
|
||||
auto dest_symbol = symbol_table.CreateSymbol("dest", false);
|
||||
auto edge_symbol = symbol_table.CreateSymbol("edge", false);
|
||||
auto lambda_node_symbol = symbol_table.CreateSymbol("n", false);
|
||||
auto lambda_edge_symbol = symbol_table.CreateSymbol("e", false);
|
||||
auto dba = db.Access();
|
||||
query::Frame frame(symbol_table.max_position());
|
||||
query::plan::ExpansionLambda filter_lambda;
|
||||
filter_lambda.inner_node_symbol = lambda_node_symbol;
|
||||
filter_lambda.inner_edge_symbol = lambda_edge_symbol;
|
||||
filter_lambda.expression = nullptr;
|
||||
query::plan::ExpandVariable expand_variable(
|
||||
nullptr, input_symbol, dest_symbol, edge_symbol,
|
||||
query::EdgeAtom::Type::DEPTH_FIRST, query::EdgeAtom::Direction::OUT, {},
|
||||
false, nullptr, nullptr, false, filter_lambda, std::nullopt,
|
||||
std::nullopt);
|
||||
// Nothing should be used from the EvaluationContext, so leave it empty.
|
||||
query::EvaluationContext evaluation_context;
|
||||
while (state.KeepRunning()) {
|
||||
query::ExecutionContext execution_context{&dba, symbol_table,
|
||||
evaluation_context};
|
||||
auto cursor = expand_variable.MakeCursor(&dba, utils::NewDeleteResource());
|
||||
for (const auto &v : dba.Vertices(dba.Label(kStartLabel), false)) {
|
||||
frame[input_symbol] = v;
|
||||
while (cursor->Pull(frame, execution_context))
|
||||
;
|
||||
}
|
||||
}
|
||||
state.SetItemsProcessed(state.iterations());
|
||||
}
|
||||
|
||||
BENCHMARK(ExpandVariableDefaultAllocator)
|
||||
->Ranges({{1, 1U << 7U}, {512, 1U << 13U}})
|
||||
->Unit(benchmark::kMillisecond);
|
||||
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
static void ExpandVariableLinearAllocator(benchmark::State &state) {
|
||||
query::AstStorage ast;
|
||||
query::Parameters parameters;
|
||||
database::GraphDb db;
|
||||
AddStarGraph(&db, state.range(0), state.range(1));
|
||||
query::SymbolTable symbol_table;
|
||||
auto input_symbol = symbol_table.CreateSymbol("input", false);
|
||||
auto dest_symbol = symbol_table.CreateSymbol("dest", false);
|
||||
auto edge_symbol = symbol_table.CreateSymbol("edge", false);
|
||||
auto lambda_node_symbol = symbol_table.CreateSymbol("n", false);
|
||||
auto lambda_edge_symbol = symbol_table.CreateSymbol("e", false);
|
||||
auto dba = db.Access();
|
||||
query::Frame frame(symbol_table.max_position());
|
||||
query::plan::ExpansionLambda filter_lambda;
|
||||
filter_lambda.inner_node_symbol = lambda_node_symbol;
|
||||
filter_lambda.inner_edge_symbol = lambda_edge_symbol;
|
||||
filter_lambda.expression = nullptr;
|
||||
query::plan::ExpandVariable expand_variable(
|
||||
nullptr, input_symbol, dest_symbol, edge_symbol,
|
||||
query::EdgeAtom::Type::DEPTH_FIRST, query::EdgeAtom::Direction::OUT, {},
|
||||
false, nullptr, nullptr, false, filter_lambda, std::nullopt,
|
||||
std::nullopt);
|
||||
// Nothing should be used from the EvaluationContext, so leave it empty.
|
||||
query::EvaluationContext evaluation_context;
|
||||
while (state.KeepRunning()) {
|
||||
query::ExecutionContext execution_context{&dba, symbol_table,
|
||||
evaluation_context};
|
||||
utils::MonotonicBufferResource memory(query::kExecutionMemoryBlockSize);
|
||||
auto cursor = expand_variable.MakeCursor(&dba, &memory);
|
||||
for (const auto &v : dba.Vertices(dba.Label(kStartLabel), false)) {
|
||||
frame[input_symbol] = v;
|
||||
while (cursor->Pull(frame, execution_context))
|
||||
;
|
||||
}
|
||||
}
|
||||
state.SetItemsProcessed(state.iterations());
|
||||
}
|
||||
|
||||
BENCHMARK(ExpandVariableLinearAllocator)
|
||||
->Ranges({{1, 1U << 7U}, {512, 1U << 13U}})
|
||||
->Unit(benchmark::kMillisecond);
|
||||
|
||||
BENCHMARK_MAIN();
|
||||
|
Loading…
Reference in New Issue
Block a user