Optimize calls via the RCUTILS_LOG macros. #369
Merged
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