flexible-collision-library / fcl

Flexible Collision Library
https://flexible-collision-library.github.io/
Other
1.39k stars 417 forks source link

update to fcl 0.6 -- slower running code #579

Open emielke12 opened 2 years ago

emielke12 commented 2 years ago

I recently had to update libraries, and went from FCL v0.5 to v0.6. As such, there was a move to a more template-oriented design, so I ended up having to explicitly type things as float or double, (i.e. when creating a fcl::OBBRSS<double> vs how it was before fcl::OBRSS. I didn't think too much of it, but this has caused a significant slow down in calls to fcl::distance.

Has anyone else seen this? I also noticed in the ROS MoveIt! libraries also have some issues related to this, where function calls and/or class instantiations are running slower.

Not sure if there's a way to get the code running as fast as it was previously, but any help would be appreciated.

jmirabel commented 2 years ago

If you really want some help, I suggest you to be more precise. E.g. give a working example with each version and the compilation line.

There are many possible reasons why this could happen, starting from compilation options.

emielke12 commented 2 years ago

Previously, I was working with code that looked something like this:

fcl::BVHModel<fcl::OBBRSS> *model = new fcl::BVHModel<fcl::OBBRSS>();
fcl::generateBVHModel(*model, fcl::Sphere(std::numeric_limits<double>::epsilon()), fcl::Matrix3f::getIdentity(), 100);
fcl::BVHModel<fcl::OBBRSS> *other_model = new fcl::BVHModel<fcl::OBBRSS>();
std::vector<fcl::Vec3f> vertices;
std::vector<fcl::Triangle> triangles;
other_model->beginModel();
... addSubModel via loop
other_model->endModel();
fcl::Transform3f I(fcl::Matrix3f::getIdentity(), fcl::Vec3f(0,0,0));
fcl::DistanceRequest request;
fcl::DistanceResult result;
fcl::distance(model, I, other_model, I, request, result);

Obviously, with v0.6 it is templatized to something like this:

fcl::BVHModel<fcl::OBBRSSd> *model = new fcl::BVHModel<fcl::OBBRSSd>();
fcl::Transform3d tf;
tf.setIdentity();
fcl::generateBVHModel(*model, fcl::Sphere<double>(std::numberic_limits<double>::epsilon()), tf, 100);
fcl::Transform3d I;
I.setIdentity();
fcl::BVHModel<fcl::OBBRSSd> *other_model = new fcl::BVHModel<fcl::OBBRSSd>();
std::vector<fcl::Vector3d> vertices;
std::vector<fcl::Triangle> triangles;
other_model->beginModel();
... addSubModel via loop
other_model->endModel();
fcl::DistanceRequest<double> request;
fcl::DistanceResult<double> result;
fcl::distance(model, I, other_model, I, request, result);

I attempted to keep everything as float, but experienced very long computation time at runtime, so I switched to double, and it's relatively close, but runs about 3 seconds slower.

Running Ubuntu 20.04, cmake compiled with GNU 9.4.0.

jmirabel commented 2 years ago

Do you use CMake option -DCMAKE_BUILD_TYPE=Release ?

Run VERBOSE=1 make and extract from the output the full compilation command. This is what tells you whether your code is truly optimized.

emielke12 commented 2 years ago

Run VERBOSE=1 make and extract from the output the full compilation command. This is what tells you whether your code is truly optimized.

I've done this, but I'm not sure I know what to look for...