Open3d: Vector3dVector function slow

Created on 21 Jun 2018  路  15Comments  路  Source: intel-isl/Open3D

Thanks for this great library.
I am using the Vector3dVector function to convert my numpy array of about 200.000 points of xyz rgb data to open3d. The functions takes about 200 ms for setting the points and the colors each. Is there any reason for this quite slow operation or anything I can do about it?

enhancement

Most helpful comment

Update:

We have heard back from Wenzel. The root cause is that we are casting a large vector of small vectors (std::vector) to python. (The new version of) Pybind11 does checks for all these casts to try to avoid copy. So in our case pybind11 does lots of checks which drag the performance down.

There are a couple of workarounds that can help this. We are looking into them and trying to find the best solution asap.

All 15 comments

Yeah it is slow. This is annoying.

import open3d
import numpy as np
x = np.random.random((200000,3))
y = open3d.Vector3dVector(x)

Takes around 100ms. Strange thing is, I tested it on a very old version of Open3D and it is blazing fast.
And it should not be slow. Under the hood it is pybind11's buffer_protocol, which should be a barebone access to the memory buffer.

We need more time to investigate.

hello... we encounter the same problem trying to visualize in realtime a PC. But Vector3dVector is really far to slow to do something workable.

I found some clue.
Before this PR https://github.com/IntelVCL/Open3D/pull/127, the following code:

import numpy as np
import time

class Timer(object):
    def __init__(self, name=None):
        self.name = name

    def __enter__(self):
        self.tstart = time.time()

    def __exit__(self, type, value, traceback):
        if self.name:
            print('[%s]' % self.name)
        print('Elapsed: %.3f' % (time.time() - self.tstart))

with Timer("Test Vector3dVector"):
    x = np.random.random((2000000,3))
    y = Vector3dVector(x)

outputs:

[Test Vector3dVector]
Elapsed: 0.398

but after the PR https://github.com/IntelVCL/Open3D/pull/127, it become

[Test Vector3dVector]
Elapsed: 2.114

However, I haven't found a solution yet. The main purpose PR was to upgrade pybind 2.0 to 2.2. I have compared commits between before and after this PR, but src/Python/py3d.h and src/Python/py3d_eigen.cpp are untouched. I think python binding of open3d need to be optimized in accordance with pybind 2.2.

Is there anyway we can identify it is a problem of pybind11 2.2 or it's a problem of our implementation? If it is a pybind11 2.2 issue, we should try their latest version or file a bug report on their repo.

Well, for us vector3dvector is a core feature of open3d. We work a lot with numpies. Not only for visualization but also for example to send realtime scan streams over tcpip to a server.
At that time, it is almost impossible, it is to slow.
Then it would be nice if this issue could be solved.

Some updates.

  • The issue persists even I tried with the recent pybind 2.2.3
  • Our code for binding seems fine, and I cannot find relevant issue or documents from pybind11
  • I opened a ticket for this issue in official pybind11 repo: https://github.com/pybind/pybind11/issues/1481

Hi!, are there some news on this issue?

The ticket on pybind11 is still hanging: pybind/pybind11#1481
Does anyone have a direct connection with the pybind11 team and can help us ping them?

Update:

We have heard back from Wenzel. The root cause is that we are casting a large vector of small vectors (std::vector) to python. (The new version of) Pybind11 does checks for all these casts to try to avoid copy. So in our case pybind11 does lots of checks which drag the performance down.

There are a couple of workarounds that can help this. We are looking into them and trying to find the best solution asap.

For people who are following this thread, @yxlao made the fix in #657 . I am reviewing it and hopefully will merge it into master during the weekend. Please test it out and let us know if this addresses the performance issue for you.

Thank you for the support! i will test it in the weekend :)

can we directly install the new version through anaconda? with pip install open3d? or should we build the new version from source?

before the next release, we'll need to build from source to get the latest version

Addressed in #657. @VinceDT @argosvr @richipower: Please check :)

When using numpy with Vector3dVector, I noticed a slow down with the visualization when the numpy array type was np.float32. Initializing my array with dtype=np.float64 (which is the default type I think), solved it for me!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lordlycastle picture lordlycastle  路  3Comments

mike239x picture mike239x  路  4Comments

blackccpie picture blackccpie  路  3Comments

DKandrew picture DKandrew  路  3Comments

nrj127 picture nrj127  路  4Comments