Skip to content

Conversation

@Flova
Copy link
Member

@Flova Flova commented May 29, 2025

Summary

Bring peak behavior CPU load from 99% to ~40% with an avg. of ~25%

Proposed changes

  • Cache frequently computed values during each tick
  • Use the events executor
  • Reduce usage of tf for simple transformations

Checklist

  • Run colcon build
  • Write documentation
  • Test on your machine
  • Test on the robot
  • Create issues for future work
  • Triage this PR and label it

@github-project-automation github-project-automation bot moved this to 🆕 New in Software May 29, 2025
@Flova Flova added the behavior label May 29, 2025
@Flova Flova moved this from 🆕 New to 🏗 In progress in Software May 29, 2025
@Flova Flova changed the base branch from main to feature/python_events_executore May 29, 2025 16:53
Copy link
Contributor

Copilot AI left a 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_buffer initialization across nodes with the new Buffer signature
  • Swapped MultiThreadedExecutor for EventsExecutor and added cache clearing
  • Introduced a @cached_capsule_function decorator 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_cache correctly 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 time may be ambiguous or collide with modules; consider renaming it to current_time or now for clarity.
def time(self) -> Time:

self.set_state_defaults()

self.tf_buffer = Buffer(self.node)
self.tf_buffer = Buffer(node=self.node)
Copy link

Copilot AI May 29, 2025

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.

Copilot uses AI. Check for mistakes.
super().__init__("bitbots_robot_filter")

self.tf_buffer = Buffer(self, Duration(seconds=10.0))
self.tf_buffer = Buffer(Duration(seconds=10.0), self)
Copy link

Copilot AI May 29, 2025

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.

Suggested change
self.tf_buffer = Buffer(Duration(seconds=10.0), self)
self.tf_buffer = Buffer(cache_time=Duration(seconds=10.0), node=self)

Copilot uses AI. Check for mistakes.
@github-project-automation github-project-automation bot moved this from 🏗 In progress to 👀 In review in Software Jun 5, 2025
@jaagut jaagut merged commit 6a59a42 into feature/python_events_executore Jun 8, 2025
2 checks passed
@jaagut jaagut deleted the feature/behavior_optimizations branch June 8, 2025 19:17
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Software Jun 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants