-
Notifications
You must be signed in to change notification settings - Fork 632
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
Modernise mrpt-graphslam lib #697
Comments
👍 to this initiative :-) My only comments are regarding:
Sometimes, leaving the full (lengthy!) types might help understanding the program. In those cases, I would consider leaving it. Now, all for loops should be ported to auto, or even better to the "for range" notation that avoids iterators at all.
Make sure of enabling all compiler warnings, or at least keep an eye on clang build logs (which seems to emit better warnings some times): in some cases, the "emplace" methods are not a gain at all, or even makes things worse if they disallow the use of RVO optimizations (copy elision).
Or even better: if no other ctor exists, just don't declare any ctor at all, given that all member variables are initialized to default values, e.g. via the Cheers! |
On Sat, Mar 24, 2018 at 11:54 PM Jose Luis Blanco-Claraco < ***@***.***> wrote:
👍 to this initiative :-)
My only comments are regarding:
Use auto instead of explicit type declarations (especially in for-loops,
assignment expressions)
Sometimes, leaving the full (lengthy!) types might help understanding the
program. In those cases, I would consider leaving it. Now, all for loops
should be ported to auto, or even better to the "for range" notation that
avoids iterators at all.
Yes, correct!
Consider emplacement instead of insertion
Make sure of enabling all compiler warnings, or at least keep an eye on
clang build logs (which seems to emit better warnings some times): in some
cases, the "emplace" methods are not a gain at all, or even makes things
worse if they disallow the use of RVO optimizations (copy elision).
Hmm, I wasn't aware of this. I am pro of the emplace_* functions instead of
push_back alternatives mainly when using it as in the following case:
// the first one is either more efficient or equivalent (in case of copy
elision) than the second one as in the case of emplace_back the object is
built in place
// see also: https://stackoverflow.com/a/11876097/2843583
vec.emplace_back(x, y);
vec.push_back(Point2d(x, y));
Replace empty constructors/destructors with =default
Or even better: if no other ctor exists, just just declare any ctor, given
that all member variables are initialized to default values, e.g. via the int
n{0}; notation.
Only advantages of =default vs the implicitly defined constructor are that
i) it's explicit and ii) it allows you to use C++11 attributes along it as
described in this SO post:
https://stackoverflow.com/questions/41219291/defaulted-constructor-vs-implicit-constructor?noredirect=1&lq=1
Cheers!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#697 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFjBj8A7yaEGtrgLxoSn3IMeYnOJICnCks5thtydgaJpZM4S5t_E>
.
--
Nikos Koukis
Robotics Engineer - SLAMcore
[email protected]
+44 902907732
|
This one suggests it is more efficient
This suggests it is less efficient.
With move semantics, the copy penalty is not a problem anymore. The inline is unnecessary, but the 2nd way is preferred. The comments are now misleading. Generally move semantics makes this efficient. Copy/move elision makes it efficient.
I think this form is prefered. I don't think it is necessary to have two versions of those getters. |
If you have an output argument consider returning it as a value, unless there is some reason why the object needs to be mutated in place. For multiple output arguments, C++17 will add structured-bindings. Until we upgrade to c++17 we can use std::tie. |
Nice one... I hadn't really considered that seriously returning non-PODs by value! |
Sure! Returning by reference is still my preferred method. But it's good to know about the optimizations of returning by value for |
Oh, totally irrelevant, but do we have some sort of a C++17-like string_view functionality in MRPT? The latter would be much more efficient than using |
Is it already supported by clang 6, GCC 7.2 and vs2017? |
I don't know... |
We can use c++14 features. |
clang-6 and gcc-7.2 both support string_view with the c++17 standard. Since c++17 support isn't quite complete though any c++17 feature must be supported by all 3 target compilers. I'd certainly prefer using std::string_view over implementing a custom one. |
@bergercookie Nope... we should (for now) stay up to C++14 for MRPT master (2.0). |
I don't remember the exact CMake commands to do this, but, it would be OK if we could set the general CMAKE_CXX_STANDARD to 14, then request additional individual features. PS: I think it's |
We could do what we did with llvm propagate_const until we want to bump the standard up to c++17. |
I just revisited this great page and found that C++17 is better supported than I imagined by GCC 7, CLANG 4 and even the latest MSVC 2017 releases. It would be great to get rid of all those alignas() by using P0035R4's overaligned new operators; an incentive to bump towards C++17. |
I just tested c++17. looks like issues in the boost python bindings. |
CLevMarqGSO_impl.h needs an CConfigFile.h, CPlanarLaserScan.h include. |
Ok, yes, that's exactly what I wanted! 👍 |
Enabling C++17 may cause us to run into this bug. |
Looks like the issue is fixed in 1.65.0. |
@bergercookie : I appended one more tasks to your list above, above converting loops to range-based loops, where applicable. |
On using string_view, it has some interesting numbers: |
Worth watching around minute 20 to see why range based loops are better. |
Awesome! I was really surprised of the closed-form summation replacement by clang (!) |
Also if you ever wanted to know if you should return string, char * or string_view from a function, then here is your answer. |
* mrpt_graphslam: Replace NULL with nullptr, simplify code comments * Add "override" directive to supress warnings * mrpt_graphslam: Use pragma once Used this script: https://github.com/marcusmueller/include-guard-convert * Add tags file to .gitignore * mrpt_graphslam: Simplify docs, mark default ctors, dtors * Move of default/initial values from the constructors to the member variables themselves in the header file. * mrpt_graphslam: Take out redundant updateStates inherited methods
Many of these "modernizations" can be greatly automated via clang-tidy: 37c5acb I've started some of them, see the latest commits; so, some points above would be done not only for graph-slam, but for the entire mrpt ;-) |
Since we have started using C++11 all over MRPT after the 1.5 release we could refactor the mrpt-graphsalm lib accordingly. Following is a list of improvements that can be implemented to clean up and modernise that code:
enum class
) to C-style unscoped enumsnoexcept functions are more optimizable than non-noexcept functions
=default
Even though such modification goes against the Google C++ Guidelines it's clearly the better approach since this way the function code doesn't have to check for null pointer and also the syntax for accessing that element is much clearer.
Using emplace/emplace_back/emplace_front creates the object directly inside the container (std::vector, std::map), avoiding the need to call the constructor and destructor of a temporary object.
CGraphSlamEngine_impl.h
for examples on this. Allocate usingmake_shared<CLASS_NAME>(), make_unique<CLASS_NAME>()
instead ofshared_ptr<CLASS_NAME>(new CLASS_NAME(...))
Declare overriding methods as override in class inheritance (see e.g., the various policies deriving from
CRegistrationDeciderOrOptimizer<GRAPH_T>
)for (iterator it=...
loops with range-based C++11for
loops.Link: https://github.com/bergercookie/mrpt/commits/mrpt-graphslam-improvements
The text was updated successfully, but these errors were encountered: