Skip to content
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

Vector3dVector function slow #403

Closed
VinceDT opened this issue Jun 21, 2018 · 17 comments
Closed

Vector3dVector function slow #403

VinceDT opened this issue Jun 21, 2018 · 17 comments

Comments

@VinceDT
Copy link

VinceDT commented Jun 21, 2018

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?

@qianyizh
Copy link
Collaborator

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.

@Fred3D-tech
Copy link

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

@syncle
Copy link
Contributor

syncle commented Jul 30, 2018

I found some clue.
Before this PR #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 #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.

@qianyizh
Copy link
Collaborator

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.

@Fred3D-tech
Copy link

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.

@syncle
Copy link
Contributor

syncle commented Aug 2, 2018

Some updates.

@richipower
Copy link

Hi!, are there some news on this issue?

@qianyizh
Copy link
Collaborator

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?

@qianyizh
Copy link
Collaborator

Update:

We have heard back from Wenzel. The root cause is that we are casting a large vector of small vectors (std::vectorEigen::Vector3d) 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.

@qianyizh
Copy link
Collaborator

qianyizh commented Nov 2, 2018

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.

@richipower
Copy link

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

@richipower
Copy link

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

@yxlao
Copy link
Collaborator

yxlao commented Nov 5, 2018

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

@syncle
Copy link
Contributor

syncle commented Dec 17, 2018

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

@syncle syncle closed this as completed Dec 17, 2018
@heethesh
Copy link
Contributor

heethesh commented Sep 3, 2020

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!

@Chris10M
Copy link

On same note as @heethesh, the hot fix is to use dtype=np.float64 for Vector3dVector and dtype=np.int32 for Vector3iVector.

@GipsonLeo
Copy link

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!

np.float64, it works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants