Optimize calls via the RCUTILS_LOG macros.#369
Merged
clalancette merged 2 commits intorollingfrom Aug 3, 2022
Merged
Conversation
It turns out that when we call RCUTILS_LOG_DEBUG (and friends), we were calling rcutils_logging_logger_is_enabled_for() twice; once in the macro itself (where we want to avoid evaluating conditions if the logger is disabled), and once in the rcutils_log() call. Since rcutils_logging_logger_is_enabled_for() is a pretty expensive function, this means we were doing unnecessary work. Improve this by splitting rcutils_log() into rcutils_log() and rcutils_log_internal(), the latter of which does not do the enabled check. Then change the macros to call the internal version of the API, which avoids the double check while still maintaining the safety guarantees we want if a user calls rcutils_log() directly. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Contributor
Author
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Collaborator
|
related to #364 |
fujitatomoya
approved these changes
Jul 31, 2022
Collaborator
fujitatomoya
left a comment
There was a problem hiding this comment.
lgtm! but adding test would be ideal.
Contributor
Author
I ended up not adding tests because I think everything here is already covered elsewhere. That is, the tests in https://github.com/ros2/rcutils/blob/rolling/test/test_logging.cpp end up testing That said, let me know if you still think I should add additional tests. |
Collaborator
|
@clalancette thanks for the comment, i am good to go with green CI. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It turns out that when we call RCUTILS_LOG_DEBUG (and friends),
we were calling rcutils_logging_logger_is_enabled_for() twice;
once in the macro itself (where we want to avoid evaluating
conditions if the logger is disabled), and once in the rcutils_log()
call. Since rcutils_logging_logger_is_enabled_for() is a pretty
expensive function, this means we were doing unnecessary work.
Improve this by splitting rcutils_log() into rcutils_log() and
rcutils_log_internal(), the latter of which does not do the
enabled check. Then change the macros to call the internal
version of the API, which avoids the double check while still
maintaining the safety guarantees we want if a user calls
rcutils_log() directly.
Signed-off-by: Chris Lalancette clalancette@openrobotics.org