ros-visualization / rqt_bag

http://wiki.ros.org/rqt_bag
30 stars 55 forks source link

[Jazzy]: rqt_bag playback uses too much CPU time #157

Open clalancette opened 4 months ago

clalancette commented 4 months ago

When playing back a bag (clicking on the "Play" button after loading a bag), rqt_bag will use 75-100% of a core to do the playback.

The reason this happens is fairly straightforward. The BagTimeline class uses a 3 millisecond timer to play data back. That ends up calling on_idle, which calls _step_playahead, which, in the case of normal playback, calls step_fixed.

Among other things, step_fixed ends up setting the playhead of the timeline frame. This one line of code hides a lot of complexity, since playhead is a property.

Essentially the reason we use so much CPU time is that set_playhead is very expensive; in my testing, it uses between 1.75 and 2 millseconds. Since that is a large fraction of the 3 millisecond timer callback, we end up using a lot of CPU time.

The solution is to try to drastically reduce the cost of calls to _set_playhead, which will allow us to use less CPU time and possibly to even increase the timer callback to 1 milliseconds instead of 3.