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

Revamp how we check for the correct class. #218

Merged
merged 2 commits into from
Oct 8, 2024

Conversation

clalancette
Copy link
Contributor

In an issue it was pointed out that we are decref'ing before we actually use some of the data, which means that in theory the garbage collector could reclaim the data before we used it. So the original point of this change was to fix that issue.

However, while looking at it I realized we could slightly improve performance here by avoiding a copy of the class and module into a combined string. Instead, we can compare them separately, which should reduce the copies.

This is a partial solution to #217 ; the other reported bug in there will require a much more extensive rework.

In an issue it was pointed out that we are decref'ing
before we actually use some of the data, which means that
in theory the garbage collector could reclaim the data
before we used it.  So the original point of this change
was to fix that issue.

However, while looking at it I realized we could slightly
improve performance here by avoiding a copy of the class
and module into a combined string.  Instead, we can compare
them separately, which should reduce the copies.

Signed-off-by: Chris Lalancette <[email protected]>
@clalancette
Copy link
Contributor Author

clalancette commented Oct 2, 2024

Pulls: #218
Gist: https://gist.githubusercontent.com/clalancette/1319b32b184fce38189666d4e4e69c43/raw/2b4fb3b5d7b2c647a8f6fe22b9010efcd374125e/ros2.repos
BUILD args: --packages-above-and-dependencies ament_cmake_core
TEST args: --packages-above ament_cmake_core
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/14647

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Since the variables are only used in an assert, which
can be compiled out, this could lead to a warning.
Inline the call instead, which should get rid of the warning.

Signed-off-by: Chris Lalancette <[email protected]>
@clalancette
Copy link
Contributor Author

I had to add a fix when building in Release mode. Another set of CI is upcoming.

@clalancette
Copy link
Contributor Author

clalancette commented Oct 2, 2024

Pulls: #218
Gist: https://gist.githubusercontent.com/clalancette/1319b32b184fce38189666d4e4e69c43/raw/2b4fb3b5d7b2c647a8f6fe22b9010efcd374125e/ros2.repos
BUILD args:
TEST args:
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/14647

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Copy link
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any issues, so LGTM!

If I were going to rewrite this module from scratch I'd make this check use PyObject_IsInstance instead of using string comparisons, but that'd require importing the class type we want to check, which we'd probably want to do once in a PyInit_*(), and I'm not sure where the PyInit_*() function even is.

@clalancette clalancette merged commit 7077033 into rolling Oct 8, 2024
3 checks passed
@clalancette clalancette deleted the clalancette/cleanup-class-checking branch October 8, 2024 12:52
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