Skip to content

Use CFFI to generate _rclpy_logging - #656

Closed
sloretz wants to merge 7 commits into
masterfrom
prototype_rclpy_cffi
Closed

sloretz wants to merge 7 commits into
masterfrom
prototype_rclpy_cffi

Conversation

@sloretz

@sloretz sloretz commented Jan 8, 2021

Copy link
Copy Markdown
Contributor

This is a prototype using the python-cffi to generate the CPython extension instead of writing it ourselves. This pull request replaces _rclpy_logging with it. This is an alternative to pybind11 and #652.

CFFI works by giving it a definition file and a bit of extra C code with all the includes for those definitions, and asking it to generate a CPython extension. That extension is then compiled by CMake, and used in the Python code. In the case of _rclpy_logging it gets rid of all the manual CPython extension writing, and in the process moving all the logic that was in C into Python instead.

@cottsay @IanTheEngineer @azeey FYI

@sloretz sloretz self-assigned this Jan 8, 2021
@sloretz

sloretz commented Jan 8, 2021

Copy link
Copy Markdown
Contributor Author

Code size comparison - very minimal increase, likely because this approach exposes more C functions and types to Python.

CMAKE_BUILD_TYPE=Debug master branch

-rw-r--r-- 1 sloretz sloretz 45K Jan  7 17:47 install/rclpy/lib/python3.8/site-packages/rclpy/_rclpy_logging.cpython-38-x86_64-linux-gnu.so

CMAKE_BUILD_TYPE=Debug this PR's branch

-rw-r--r-- 1 sloretz sloretz 53K Jan  7 17:37 install/rclpy/lib/python3.8/site-packages/rclpy/_rclpy_logging.cpython-38-x86_64-linux-gnu.so

@sloretz

sloretz commented Jan 8, 2021

Copy link
Copy Markdown
Contributor Author

CI (build: --packages-above-and-dependencies rclpy test: --packages-above rclpy CI branch: add_python3_cffi)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@sloretz

sloretz commented Jan 8, 2021

Copy link
Copy Markdown
Contributor Author

CI again with two new commits + rebased ros2/ci#531 for flak8 workaround

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@sloretz

sloretz commented Jan 9, 2021

Copy link
Copy Markdown
Contributor Author

Windows again with debug code: Build Status

@ivanpauno

Copy link
Copy Markdown
Member

Related to the comment here, I think that if we use cffi for all our bindings ensuring that objects are destroyed in the correct order will be quite complicated.

@sloretz

sloretz commented Jan 12, 2021

Copy link
Copy Markdown
Contributor Author

Related to the comment here, I think that if we use cffi for all our bindings ensuring that objects are destroyed in the correct order will be quite complicated.

Yeah, making sure publishers are destroyed before nodes etc is more complicated than what can be done with Pybind11. CFFI offers essentially the same capability as pycapsule destructors, so it would be about the same complexity as it is now.

Upstream thoughts on destruction order
https://foss.heptapod.net/pypy/cffi/-/issues/340

Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
@sloretz
sloretz force-pushed the prototype_rclpy_cffi branch from c2fc875 to 6c7c0b4 Compare January 15, 2021 00:29
Signed-off-by: Shane Loretz <[email protected]>
@sloretz

sloretz commented Jan 21, 2021

Copy link
Copy Markdown
Contributor Author

Closing; future work in #665

@sloretz sloretz closed this Jan 21, 2021
@sloretz
sloretz deleted the prototype_rclpy_cffi branch January 21, 2021 18:41
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

Successfully merging this pull request may close these issues.

2 participants