8000 save some overhead when walking plans · ezhangle/arangodb@cdfdec9 · GitHub
[go: up one dir, main page]

Skip to content

Commit cdfdec9

Browse files
committed
save some overhead when walking plans
1 parent 9791e46 commit cdfdec9

15 files changed

+379
-292
lines changed

arangod/Aql/Ast.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,8 +1439,9 @@ void Ast::validateAndOptimize () {
14391439
/// @brief determines the variables referenced in an expression
14401440
////////////////////////////////////////////////////////////////////////////////
14411441

1442-
std::unordered_set<Variable*> Ast::getReferencedVariables (AstNode const* node) {
1443-
auto visitor = [&](AstNode const* node, void* data) -> void {
1442+
void Ast::getReferencedVariables (AstNode const* node,
1443+
std::unordered_set<Variable*>& result) {
1444+
auto visitor = [](AstNode const* node, void* data) -> void {
14441445
if (node == nullptr) {
14451446
return;
14461447
}
@@ -1455,15 +1456,12 @@ std::unordered_set<Variable*> Ast::getReferencedVariables (AstNode const* node)
14551456

14561457
if (variable->needsRegister()) {
14571458
auto result = static_cast<std::unordered_set<Variable*>*>(data);
1458-
result->insert(variable);
1459+
result->emplace(variable);
14591460
}
14601461
}
14611462
};
14621463

1463-
std::unordered_set<Variable*> result;
14641464
traverseReadOnly(node, visitor, &result);
1465-
1466-
return result;
14671465
}
14681466

14691467
////////////////////////////////////////////////////////////////////////////////
@@ -2477,7 +2475,7 @@ AstNode* Ast::traverseAndModify (AstNode* node,
24772475
size_t const n = node->numMembers();
24782476

24792477
for (size_t i = 0; i < n; ++i) {
2480-
auto member = node->getMember(i);
2478+
auto member = node->getMemberUnchecked(i);
24812479

24822480
if (member != nullptr) {
24832481
AstNode* result = traverseAndModify(member, preVisitor, visitor, postVisitor, data);
@@ -2508,7 +2506,7 @@ AstNode* Ast::traverseAndModify (AstNode* node,
25082506
size_t const n = node->numMembers();
25092507

25102508
for (size_t i = 0; i < n; ++i) {
2511-
auto member = node->getMember(i);
2509+
auto member = node->getMemberUnchecked(i);
25122510

25132511
if (member != nullptr) {
25142512
AstNode* result = traverseAndModify(member, visitor, data);
@@ -2539,7 +2537,7 @@ void Ast::traverseReadOnly (AstNode const* node,
25392537
size_t const n = node->numMembers();
25402538

25412539
for (size_t i = 0; i < n; ++i) {
2542-
auto member = node->getMember(i);
2540+
auto member = node->getMemberUnchecked(i);
25432541

25442542
if (member != nul 8000 lptr) {
25452543
traverseReadOnly(member, preVisitor, visitor, postVisitor, data);
@@ -2564,7 +2562,7 @@ void Ast::traverseReadOnly (AstNode const* node,
25642562
size_t const n = node->numMembers();
25652563

25662564
for (size_t i = 0; i < n; ++i) {
2567-
auto member = node->getMember(i);
2565+
auto member = node->getMemberUnchecked(i);
25682566

25692567
if (member != nullptr) {
25702568
traverseReadOnly(const_cast<AstNode const*>(member), visitor, data);

arangod/Aql/Ast.h

Lines changed: 2 additions & 1 deletion
8000
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,8 @@ namespace triagens {
598598
/// @brief determines the variables referenced in an expression
599599
////////////////////////////////////////////////////////////////////////////////
600600

601-
static std::unordered_set<Variable*> getReferencedVariables (AstNode const*);
601+
static void getReferencedVariables (AstNode const*,
602+
std::unordered_set<Variable*>&);
602603

603604
////////////////////////////////////////////////////////////////////////////////
604605
/// @brief determines the top-level attributes in an expression, grouped by

arangod/Aql/ExecutionBlock.cpp

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -258,41 +258,6 @@ void ExecutionBlock::throwIfKilled () {
258258
}
259259
}
260260

261-
////////////////////////////////////////////////////////////////////////////////
262-
/// @brief functionality to walk an execution block recursively
263-
////////////////////////////////////////////////////////////////////////////////
264-
265-
bool ExecutionBlock::walk (WalkerWorker<ExecutionBlock>* worker) {
266-
// Only do every node exactly once:
267-
if (worker->done(this)) {
268-
return false;
269-
}
270-
271-
if (worker->before(this)) {
272-
return true;
273-
}
274-
275-
// Now the children in their natural order:
276-
for (auto& c : _dependencies) {
277-
if (c->walk(worker)) {
278-
return true;
279-
}
280-
}
281-
// Now handle a subquery:
282-
if (_exeNode->getType() == ExecutionNode::SUBQUERY) {
283-
auto p = static_cast<SubqueryBlock*>(this);
284-
if (worker->enterSubquery(this, p->getSubquery())) {
285-
bool abort = p->getSubquery()->walk(worker);
286-
worker->leaveSubquery(this, p->getSubquery());
287-
if (abort) {
288-
return true;
289-
}
290-
}
291-
}
292-
worker->after(this);
293-
return false;
294-
}
295-
296261
////////////////////////////////////////////////////////////////////////////////
297262
/// @brief initialize
298263
////////////////////////////////////////////////////////////////////////////////
@@ -1373,7 +1338,8 @@ int IndexRangeBlock::initialize () {
13731338
_inRegs.emplace_back();
13741339
std::vector<RegisterId>& inRegsCur = _inRegs.back();
13751340

1376-
std::unordered_set<Variable*>&& inVars = expression->variables();
1341+
std::unordered_set<Variable*> inVars;
1342+
expression->variables(inVars);
13771343

13781344
for (auto const& v : inVars) {
13791345
inVarsCur.emplace_back(v);
@@ -2794,7 +2760,9 @@ CalculationBlock::CalculationBlock (ExecutionEngine* engine,
27942760
_inRegs(),
27952761
_outReg(ExecutionNode::MaxRegisterId) {
27962762

2797-
std::unordered_set<Variable*> const& inVars = _expression->variables();
2763+
std::unordered_set<Variable*> inVars;
2764+
_expression->variables(inVars);
2765+
27982766
_inVars.reserve(inVars.size());
27992767
_inRegs.reserve(inVars.size());
28002768

@@ -6053,7 +6021,6 @@ bool BlockWithClients::skipForShard (size_t number,
60536021
size_t BlockWithClients::getClientId (std::string const& shardId) {
60546022
ENTER_BLOCK
60556023
if (shardId.empty()) {
6056-
TRI_ASSERT(false);
60576024
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "got empty shard id");
60586025
}
60596026

arangod/Aql/ExecutionBlock.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,19 @@ namespace triagens {
145145

146146
void throwIfKilled ();
147147

148-
////////////////////////////////////////////////////////////////////////////////
149-
/// @brief functionality to walk an execution block recursively
150-
////////////////////////////////////////////////////////////////////////////////
151-
152-
bool walk (WalkerWorker<ExecutionBlock>* worker);
153-
154148
////////////////////////////////////////////////////////////////////////////////
155149
/// @brief add a dependency
156150
////////////////////////////////////////////////////////////////////////////////
157151

158152
void addDependency (ExecutionBlock* ep) {
159-
_dependencies.push_back(ep);
153+
_dependencies.emplace_back(ep);
160154
}
161155

162156
////////////////////////////////////////////////////////////////////////////////
163157
/// @brief get all dependencies
164158
////////////////////////////////////////////////////////////////////////////////
165159

166-
std::vector<ExecutionBlock*> getDependencies () {
160+
std::vector<ExecutionBlock*> getDependencies () const {
167161
return _dependencies;
168162
}
169163

arangod/Aql/ExecutionEngine.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,15 @@ struct Instanciator : public WalkerWorker<ExecutionNode> {
250250
TRI_ASSERT(block != nullptr);
251251

252252
// Now add dependencies:
253-
std::vector<ExecutionNode*> const& deps = en->getDependencies();
253+
std::vector<ExecutionNode*> const& deps = en->getDependenciesReference();
254254

255255
for (auto const& it : deps) {
256256
auto it2 = cache.find(it);
257257
TRI_ASSERT(it2 != cache.end());
258258
block->addDependency(it2->second);
259259
}
260260

261-
cache.emplace(std::make_pair(en, block));
261+
cache.emplace(en, block);
262262
}
263263

264264
};
@@ -702,7 +702,7 @@ struct CoordinatorInstanciator : public WalkerWorker<ExecutionNode> {
702702
throw;
703703
}
704704

705-
std::vector<ExecutionNode*> deps = (*en)->getDependencies();
705+
std::vector<ExecutionNode*> deps = (*en)->getDependenciesReference();
706706

707707
for (auto dep = deps.begin(); dep != deps.end(); ++dep) {
708708
auto d = cache.find(*dep);

0 commit comments

Comments
 (0)
0