nanoflann icon indicating copy to clipboard operation
nanoflann copied to clipboard

findNeighbors is slow for repeated calls, would be faster with caching in leaves

Open froody opened this issue 3 years ago • 2 comments

I'm using findNeighbors via PDAL filters.icp, and the general algorithm is (pseudocode):

# Given two point clouds A and B
iterations = 100 # customizable
kdtree = KDTree(A)
for i in iterations:
    for point in B:
        kdtree.findNeighbours(point, 1)
    B = applyTransform(B)

This leads to poor data locality with repeated call to kdtree_get_pt for each iteration. I have a fix which caches points in leaf Node instances, and this leads to a ~3x performance increase in my limited testing. I can create a pull request if this is something of interest.

froody avatar Dec 07 '20 00:12 froody

There's probably some trade-off, but yes please go on and propose a PR.

Thanks!

jlblancoc avatar Dec 07 '20 14:12 jlblancoc

@froody hello, do you still have the implementation by any chance? I have an iterative algorithm that needs every speedup it can get.

I can clean it up and create a pull request if you like. It would be much appreciated.

Thank you!

yasamoka avatar Apr 25 '22 02:04 yasamoka