Skip to content

Reduce memory allocations in IK solvers #629

Open

Description

@davetcoleman

It was requested in pull request by @Jmeyer1292 that the IKFast and KDL IK solvers reduce memory allocation during runtime and instead only allocate at initialization. Even though we do not make any runtime guarantees, IK is called so frequently during some types of planning that we would see large speedups.

This changes should be relatively simple and ideal for a World MoveIt! Day project. Be sure to test against moveit_kinematics_tests for any breakages.

Activity

  1. added
    moveit day candidate
    simple improvements
    on Oct 11, 2017
  2. removed
    simple improvements
    on Oct 11, 2017
  3. v4hn commented on Oct 11, 2017

    @v4hn
    Contributor

    Great idea!

    I believe this is not simple though. Things can get ugly if you look into thread-safety - I'm uncertain about whether we currently guarantee it, but we want to aim for it either way.

  4. gavanderhoorn commented on Oct 11, 2017

    @gavanderhoorn
    Member

    I would suggest to 'require' that a potential taker of this enhancement first profile a typical kinematics solver to see whether there is a lot of overhead in however many dynamic allocations they might do.

    I trust @Jmeyer1292, but it would be a shame if someone spends their WMD figuring out how to avoid all sorts of allocs to in the end not really see any large improvement.

    Do you have any nrs @Jmeyer1292 ?

  5. Jmeyer1292 commented on Oct 11, 2017

    @Jmeyer1292

    My comment was more specifically targeted at the PR that @davetcoleman mentioned because it seemed to do a lot of work for little gain: it made an extra vector and sorted it when all that needed to happen was to linearly march over existing data and remember the best item. It was an offhand comment and I have no data to back it up.

    To the point made by @v4hn, MoveIt's API makes removing allocations difficult in a threaded environment. I wouldn't bother with it.

  6. v4hn commented on Oct 11, 2017

    @v4hn
    Contributor

    Nevertheless, I believe at least profiling the current kinematics plugins to see how much it could improve is a good idea for WMD.

  7. marip8 commented on Oct 18, 2017

    @marip8

    I will start working on this

  8. added
    assigned
    on Oct 18, 2017
  9. marip8 commented on Oct 18, 2017

    @marip8

    test

    I created a test node that solves a Motoman ES200RN-120's kinematics at 10k unique poses (in a ~1x1m vertical grid in front of the robot) using the IKFast plugin, and I profiled it with valgrind.

    The results show that the getPositionIK function spends about 6.5% of its time sorting the list of potential solutions to get the closest solution to the seed (std::sort and LimitObeyingSol). That doesn't seem to be too much of a time-sink, but there does seem to be a lot of time spent in other overhead functions (i.e ~20% of time in getSolution, etc.)

  10. Jmeyer1292 commented on Oct 19, 2017

    @Jmeyer1292

    Definitely less time than I thought, but still enough to be appreciable.

    The real stand out here is the crazy amount of overhead associated with IKFast's API. A std::list, really? It seems like maybe 25% of the time is spent doing math.

  11. davetcoleman commented on Oct 19, 2017

    @davetcoleman
    MemberAuthor

    Thanks for looking into this!

  12. simonschmeisser commented on Nov 12, 2017

    @simonschmeisser
    Contributor

    slightly offtopic: can you provide a link/repo for how you created that measurement and that fancy graphic?

  13. marip8 commented on Nov 13, 2017

    @marip8

    For the profiler I used valgrind, and the graphic was created using kcachegrind

  14. removed
    assigned
    on Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    moveit day candidate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions