Skip to content

Optimize by removing extra loop and using emplace#494

Closed
saurabh1002 wants to merge 2 commits into
mainfrom
gupta/optims
Closed

Optimize by removing extra loop and using emplace#494
saurabh1002 wants to merge 2 commits into
mainfrom
gupta/optims

Conversation

@saurabh1002

Copy link
Copy Markdown
Contributor

This pull request mainly refactors Update function in the VoxelHashMap to improve code efficiency in how voxel maps are updated.

  • Refactored VoxelHashMap::Update to transform and insert points into the voxel map in-place, avoiding creation of an intermediate transformed points vector and using emplace for more efficient map insertion.
  • Changed VoxelHashMap::AddPoints and VoxelDownsample to use emplace instead of insert for more efficient and concise map population.
  • Simplified return statements in VoxelHashMap::GetClosestNeighbor and BuildLinearSystem

Copilot AI review requested due to automatic review settings April 27, 2026 08:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors voxel map update and insertion paths to reduce intermediate allocations and simplify some return statements, aiming to improve runtime efficiency in the C++ KISS-ICP core mapping/registration pipeline.

Changes:

  • Refactor VoxelHashMap::Update(points, pose) to transform and insert points directly into the voxel map.
  • Switch map population from insert to emplace in voxel downsampling and point addition.
  • Simplify return statements in GetClosestNeighbor and BuildLinearSystem.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
cpp/kiss_icp/core/VoxelUtils.cpp Uses emplace when populating the voxel grid during downsampling.
cpp/kiss_icp/core/VoxelHashMap.cpp In-place transform+insert logic for pose-based updates; minor return simplification; uses emplace for new voxels.
cpp/kiss_icp/core/Registration.cpp Stores parallel_reduce result and returns it directly instead of structured binding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cpp/kiss_icp/core/VoxelHashMap.cpp
Comment on lines +90 to +111
const double map_resolution = std::sqrt(voxel_size_ * voxel_size_ / max_points_per_voxel_);
std::for_each(points.cbegin(), points.cend(), [&](const auto &point) {
const Eigen::Vector3d transformed_point = pose * point;
const auto voxel = PointToVoxel(transformed_point, voxel_size_);
auto search = map_.find(voxel);
if (search != map_.end()) {
auto &voxel_points = search.value();
if (voxel_points.size() == max_points_per_voxel_ ||
std::any_of(voxel_points.cbegin(), voxel_points.cend(),
[&](const auto &voxel_point) {
return (voxel_point - transformed_point).norm() < map_resolution;
})) {
return;
}
voxel_points.emplace_back(transformed_point);
} else {
std::vector<Eigen::Vector3d> voxel_points;
voxel_points.reserve(max_points_per_voxel_);
voxel_points.emplace_back(transformed_point);
map_.emplace(voxel, std::move(voxel_points));
}
});
Comment on lines 101 to +120
@@ -117,7 +117,7 @@ LinearSystem BuildLinearSystem(const Correspondences &correspondences, const dou
// 2nd Lambda: Parallel reduction of the private Jacboians
sum_linear_systems);

return {JTJ, JTr};
return linear_system;
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@saurabh1002 saurabh1002 marked this pull request as draft April 27, 2026 08:34
@saurabh1002

Copy link
Copy Markdown
Contributor Author

Nevermind, all of this is useless. Only helped me to learn about possible SIMD optimizations.

@saurabh1002 saurabh1002 deleted the gupta/optims branch April 27, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants