Skip to content

Commit

Permalink
Move parameter blocks vector outside loop
Browse files Browse the repository at this point in the history
This reduces the amount of allocations required, since the same vector
and its previously allocated memory is reused among all the graph
constraints when the ceres::Problem is created.
  • Loading branch information
efernandez committed Dec 3, 2020
1 parent 4cb9e95 commit 9539dd6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fuse_graphs/src/hash_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,12 @@ void HashGraph::createProblem(ceres::Problem& problem) const
}
}
// Add the constraints
std::vector<double*> parameter_blocks;
for (auto& uuid__constraint : constraints_)
{
fuse_core::Constraint& constraint = *(uuid__constraint.second);
// We need the memory address of each variable value referenced by this constraint
std::vector<double*> parameter_blocks;
parameter_blocks.clear();
parameter_blocks.reserve(constraint.variables().size());
for (const auto& uuid : constraint.variables())
{
Expand Down

0 comments on commit 9539dd6

Please sign in to comment.