BlueBrain / MorphIO

A python and C++ library for reading and writing neuronal morphologies
https://morphio.readthedocs.io
Apache License 2.0
26 stars 24 forks source link

Return views to C++ objects instead of copies #367

Open adrien-berchet opened 2 years ago

adrien-berchet commented 2 years ago

As far as I can see, the Python bindings of the functions and methods of MorphIO return copies of C++ data instead of views to these data. It seems possible to return views: https://github.com/pybind/pybind11/issues/2271 which would probably improve performance and reduce memory usage.

mgeplf commented 2 years ago

Which calls are you specifically thinking about? IIRC, the immutable_morph::points and immutable_morph::section_offsets do a no copy version already.

mgeplf commented 2 years ago

(oops, just checked, section_offsets makes a copy - points looks right though)

adrien-berchet commented 2 years ago

As far as I can remember, #359 was done because the points method returns a copy. @eleftherioszisis did some tests to show that it is actually a copy, I don't know if he still has them?

mgeplf commented 2 years ago

Very good point, we'll look into it.

One thing we have to be careful about is making sure that the python bindings aren't a backdoor to modifying the morphology.

eleftherioszisis commented 2 years ago

I have made an attempt to build on top of Mike's initial implementation in #373 . The lifetimes, refcounts, etc. all seem to work except for the Vasculature's last section, which seems to exhibit an issue with its refcount.