Optimize by removing extra loop and using emplace#494
Closed
saurabh1002 wants to merge 2 commits into
Closed
Conversation
There was a problem hiding this comment.
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
inserttoemplacein voxel downsampling and point addition. - Simplify return statements in
GetClosestNeighborandBuildLinearSystem.
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 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>
Contributor
Author
|
Nevermind, all of this is useless. Only helped me to learn about possible SIMD optimizations. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request mainly refactors
Updatefunction in theVoxelHashMapto improve code efficiency in how voxel maps are updated.VoxelHashMap::Updateto transform and insert points into the voxel map in-place, avoiding creation of an intermediate transformed points vector and usingemplacefor more efficient map insertion.VoxelHashMap::AddPointsandVoxelDownsampleto useemplaceinstead ofinsertfor more efficient and concise map population.VoxelHashMap::GetClosestNeighborandBuildLinearSystem