-
Notifications
You must be signed in to change notification settings - Fork 3
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
Speed up rclpy
loggers
#84
Conversation
Thanks for proposing a quick alternative solution! Would you mind elaborating on what the issues in the original code were and how the new change addresses them? |
80bb4aa
to
1cc42c5
Compare
Signed-off-by: Michel Hidalgo <[email protected]>
1cc42c5
to
b495bf3
Compare
I updated the PR description. I think it's a combination of factors that can be summarized as "too much work on every log call". This patch addresses this issue by "doing less work and only on first log call". |
throttle_duration_sec: typing.Optional[float] = None, | ||
throttle_time_source: typing.Optional[Clock] = None, | ||
skip_first: typing.Optional[bool] = None, | ||
once: typing.Optional[bool] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between None
and False
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this context, none. I annotate optional arguments as optional purely out of habit (and for the sake of readability).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, not going to block on this.
I think whether bool = False
or Optional[bool] = None
is more readable is another discussion lol. I do think there is a difference between Optional
and has a default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting a quick workaround! I wonder if we would like to contribute this change back to ROS2 as well?
I am looking forward to seeing this change live from the bdai container soon! I had to suppress a lot of log messages currently to get around the performance issue. |
return log | ||
|
||
|
||
class MemoizingRcutilsLogger: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This this class name a standard one? The name (memoizing
) sounds a bit new to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not standard, no. Memoizing is me adjectivizing memoization.
I'm onboard.
Note you will have to wrap your logger, like |
This patch introduces an alternative implementation of the
rclpy.logging.RcutilsLogger
that will cache log call configurations. This has been observed to reduce the average logging time significantly.As to why this is the case, other than the obvious advantage of executing code on first call rather than on every call, I suspect stack frame inspection in Python may be taking some amount of time (as it fetches code from source files by default when populating frame info and traceback objects, see here).