-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
From new
to pcl::make_shared
using clang-tidy
#3206
From new
to pcl::make_shared
using clang-tidy
#3206
Conversation
I just checked the CI errors and some of the replaces got botched up, e.g.:
|
786845e
to
4174056
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've aborted the review of this PR early on because it has some recurring issues. After you rebase things, I would recommend going through the diff and reviewing the changes you made in more detail. I don't thing clang-tidy will be enough here.
@@ -73,7 +75,7 @@ namespace pcl | |||
mls.process(*filtered); | |||
|
|||
processed.reset(new pcl::PointCloud<PointInT>); | |||
normals.reset (new pcl::PointCloud<pcl::Normal>); | |||
normals = pcl::make_shared<pcl::PointCloud<pcl::Normal>> (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line above this one should also be replaced no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PointInT
is a template parameter, I didn't test for that and apparently the check is failing with those. As is, I also have a failing test for when there is typedef boost::shared_ptr<Derived> Ptr;
@@ -77,7 +79,7 @@ namespace pcl | |||
mls.process (*filtered); | |||
|
|||
processed.reset (new pcl::PointCloud<PointInT>); | |||
normals.reset (new pcl::PointCloud<pcl::Normal>); | |||
normals = pcl::make_shared<pcl::PointCloud<pcl::Normal>> (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before.
@@ -377,7 +379,7 @@ template<template<class > class Distance, typename PointInT, typename FeatureT> | |||
boost::shared_ptr < std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > > transforms_temp; | |||
|
|||
models_temp.reset (new std::vector<ModelT>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use std::make_shared here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is replacement of every reset
with make_shared
our goal? Personally, I see reset
-based code as more maintainable in a sense that it does not need to know whether the pointer is std
or boost
.
@@ -377,7 +379,7 @@ template<template<class > class Distance, typename PointInT, typename FeatureT> | |||
boost::shared_ptr < std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > > transforms_temp; | |||
|
|||
models_temp.reset (new std::vector<ModelT>); | |||
transforms_temp.reset (new std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> >); | |||
transforms_temp = pcl::make_shared<std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> >> (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, you can't use pcl::make_shared
here. Notice this object has a custom allocator but won't have the necessary trait in order for dispatching to work properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case the custom allocator is for contained objects, not the vector itself. Therefore, default allocator is suitable for the vector. However, I'd invoke the same comment as above here, in my opinion no need to replace reset
with make_shared
.
@@ -598,7 +600,7 @@ template<template<class > class Distance, typename PointInT, typename FeatureT> | |||
boost::shared_ptr < std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > > transforms_temp; | |||
|
|||
models_temp.reset (new std::vector<ModelT>); | |||
transforms_temp.reset (new std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> >); | |||
transforms_temp = pcl::make_shared<std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> >> (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here for line 602 and 603.
I'm moving this answer to "global scope" because it is affects the entire PR.
I thought that was the goal: having the one time allocation and prevent mem leaks in those very unlikely corner cases. I also understand your maintainability point but isn't it just a temporary thing? I.e., if we halt this PR until the boost -> std pointer migration is complete, then it no longer matters, because there should only exist std pointers in the code base. That being said, this PR carries a lot of changes. I would really prefer to have this split by module so that we can progressively merge things and evaluate the results in the following days. |
This is true. However I should admit that as part of migration effort I'm generally trying to convert
👍 |
I would say yes, but I feel I don't have a good answer for this. I suspect this might generate some compilation issues during the transition period, in case some modules are already transitioned to std shared/unique pointers and others not. I still expect the compiler to simply fail, so we can always adjust whatever needed accordingly. If there was no penalty in the time invested, I would really finish the transition as you're doing right now and only then start applying |
On an somewhat related note, Clang and GCC both show a 10% performance difference. This only matters in the hot path, so if
Maybe this helps you in making a good tradeoff |
It would still carry the benefit of maintainers/contributors (same as end-users) not having to know which objects require custom allocation, and not having as many raw
If this graph is accurate I'm thinking it might work for some groupings of modules, potentially making it ok for review as well. E.g. keypoints, registration, search, surface, tracking, visualization, should all go down easily, then continue from there? Am I missing something? BTW the code for the clang-tidy check is 99% the same as the one for modernize-make-shared (check and test) if it helps understand why it fails here and there. |
4174056
to
e949c49
Compare
@kunaltyagi thank you for the extra insight. In my experience, there should not exist shared pointers created being inside hot loops. Hot loops in PCL only tend happen inside computation classes. These don't usually allocate more than a couple of shared pointers if any. @aPonza I'm not sure I conveyed the issue properly or I am simply not understanding your followup comments. If we already migrate |
No I'm the one who hadn't understood. I was thinking (e.g. in keypoints) about:
|
Takes all the relevant commits from #3146 and rebases them on the branch from #3163.