MorphIO icon indicating copy to clipboard operation
MorphIO copied to clipboard

Return views to C++ objects instead of copies

Open adrien-berchet opened this issue 3 years ago • 5 comments

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.

adrien-berchet avatar Jan 10 '22 09:01 adrien-berchet

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

mgeplf avatar Jan 10 '22 10:01 mgeplf

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

mgeplf avatar Jan 10 '22 10:01 mgeplf

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?

adrien-berchet avatar Jan 10 '22 10:01 adrien-berchet

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.

mgeplf avatar Jan 10 '22 11:01 mgeplf

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.

eleftherioszisis avatar Feb 02 '22 11:02 eleftherioszisis