Update just pycapsule lib to use pybind11#652
Conversation
|
Code size increase Build type DebugThe size of the pybind11 version is almost 50 times bigger than master master $ ls -l _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.so
-rw-r--r-- 1 sloretz sloretz 36608 Dec 22 14:54 _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.sothis branch $ ls -l _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.so
-rw-r--r-- 1 sloretz sloretz 1810720 Dec 22 14:52 _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.soBuild type NoneThe size of the pybind11 version is a little over 13 times bigger than master master $ ls -l _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.so
-rw-r--r-- 1 sloretz sloretz 17408 Dec 22 14:58 _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.sothis branch $ ls -l _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.so
-rw-r--r-- 1 sloretz sloretz 232800 Dec 22 14:59 _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.soBuild type ReleaseThe size of the pybind11 version is a little over 5 times bigger than master master $ ls -l _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.so
-rw-r--r-- 1 sloretz sloretz 17400 Dec 22 15:02 _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.sothis branch $ ls -l _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.so
-rw-r--r-- 1 sloretz sloretz 93304 Dec 22 15:01 _rclpy_pycapsule.cpython-38-x86_64-linux-gnu.so |
|
@azeey FYI |
|
A 5 times code size increase (at best) seems like a lot for what is essentially a lateral move for this code. If you are using the Python bindings at all, code size and performance are probably not your top concern, but it is still very large. The question I have to ask is: given that we already have a working version of the hand-coded version of this library, does the move to pybind11 still make sense? That is, does the move have enough benefits that we are willing to take a 5-50 times increase in compiled code size? I don't have a good answer for that, and I'll leave it to the maintainers of rclpy to answer. But I do think it should be considered. |
IMO, one of the biggest pain points of the current implementation is object lifetimes. If we move to pybind11 and don't use capsules at all, pybind11 smart pointers support might make things a lot easier. |
|
I'll also note that we could do a C++ implementation, and manage object lifetimes via C++ destructors - there's nothing forcing us to do a pure-c implementation as far as I can tell. If we created simple C++ wrapper objects for the CPython API objects - it would probably remove a lot of the lifetime management code. These might be easier to expose with pybind, as well. Has it been considered to just selectively expose |
fb82e2a to
9132234
Compare
|
Rebased on #667
@emersonknapp Definitely. Converting 1-to-1 is a hopefully quick process that will uncover any spots that are sensitive to pybind11's overhead. Using C++ and RAII comes after and adds a lot of benefit. You might be interested in the doc in #665. |
a11af4b to
850e84b
Compare
c04dc58 to
674b02c
Compare
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
9132234 to
7b48d74
Compare
Follow up test from #651
This updates the
_rclpy_pycapsulelib to use Pybind11 instead of raw CPython APIs where possible. Pybind11 would enablerclpyto not usepycapsuleat all if we made some thin C++ classes, but that would take a bit of refactoring. This PR looks at translating the APIs to pybind11 without any changes. This might be a good intermediate step in moving rclpy to pybind11.@cottsay @IanTheEngineer FYI