-
Notifications
You must be signed in to change notification settings - Fork 18
Behavior optimizations #692
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
Behavior optimizations #692
Conversation
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.
Pull Request Overview
This PR optimizes CPU usage by caching repeated computations, standardizing TF buffer initialization, switching to a lighter weight executor, and replacing costly TF transforms with direct numpy operations.
- Standardized
tf_bufferinitialization across nodes with the newBuffersignature - Swapped
MultiThreadedExecutorforEventsExecutorand added cache clearing - Introduced a
@cached_capsule_functiondecorator and applied it to expensive capsule methods
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| bitbots_world_model/bitbots_robot_filter/bitbots_robot_filter/filter.py | Reordered Buffer arguments for tf_buffer |
| bitbots_world_model/bitbots_ball_filter/bitbots_ball_filter/ball_filter.py | Reordered Buffer arguments for tf_buffer |
| bitbots_team_communication/bitbots_team_communication/bitbots_team_communication/bitbots_team_communication.py | Changed tf_buffer to use named argument |
| bitbots_navigation/bitbots_path_planning/bitbots_path_planning/path_planning.py | Reordered Buffer arguments for tf_buffer |
| bitbots_behavior/bitbots_body_behavior/bitbots_body_behavior/bitbots_body_behavior.py | Replaced MultiThreadedExecutor with EventsExecutor |
| bitbots_behavior/bitbots_blackboard/bitbots_blackboard/capsules/world_model_capsule.py | Added caching decorator and replaced TF-based transform with numpy |
| bitbots_behavior/bitbots_blackboard/bitbots_blackboard/capsules/team_data_capsule.py | Applied @cached_capsule_function to team data methods |
| bitbots_behavior/bitbots_blackboard/bitbots_blackboard/capsules/init.py | Defined cached_capsule_function and added per-capsule cache |
| bitbots_behavior/bitbots_blackboard/bitbots_blackboard/body_blackboard.py | Added clear_cache to flush all capsule caches |
Comments suppressed due to low confidence (2)
bitbots_behavior/bitbots_blackboard/bitbots_blackboard/capsules/init.py:11
- The new caching decorator introduces stateful behavior; consider adding unit tests to verify that caching and
clear_cachecorrectly store and invalidate results.
def cached_capsule_function(method):
bitbots_behavior/bitbots_blackboard/bitbots_blackboard/capsules/team_data_capsule.py:72
- [nitpick] The method name
timemay be ambiguous or collide with modules; consider renaming it tocurrent_timeornowfor clarity.
def time(self) -> Time:
bitbots_behavior/bitbots_blackboard/bitbots_blackboard/capsules/world_model_capsule.py
Show resolved
Hide resolved
bitbots_behavior/bitbots_blackboard/bitbots_blackboard/capsules/world_model_capsule.py
Show resolved
Hide resolved
| self.set_state_defaults() | ||
|
|
||
| self.tf_buffer = Buffer(self.node) | ||
| self.tf_buffer = Buffer(node=self.node) |
Copilot
AI
May 29, 2025
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.
Other TF buffers in this project specify a cache duration; relying on the default may lead to inconsistency. Consider passing the intended Duration explicitly.
| super().__init__("bitbots_robot_filter") | ||
|
|
||
| self.tf_buffer = Buffer(self, Duration(seconds=10.0)) | ||
| self.tf_buffer = Buffer(Duration(seconds=10.0), self) |
Copilot
AI
May 29, 2025
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.
[nitpick] Using positional parameters for the new Buffer signature can be less clear. Consider switching to named arguments (e.g., Buffer(cache_time=Duration(...), node=self)) for readability.
| self.tf_buffer = Buffer(Duration(seconds=10.0), self) | |
| self.tf_buffer = Buffer(cache_time=Duration(seconds=10.0), node=self) |
Summary
Bring peak behavior CPU load from 99% to ~40% with an avg. of ~25%
Proposed changes
Checklist
colcon build