Creating ROS Message objects is much slower in R2021a than in R2019b.
1 view (last 30 days)
The way MATLAB handles ROS message objects changed much in one of the recent releases of Matlab.
Sadly, I noticed a significant performance loss when creating ROS message objects even with simple messages like std_msgs/Float64.
Consider the following snippet:
In R2019b, the object creation takes approximately 1 ms:
Elapsed time is 0.001047 seconds.
Elapsed time is 0.000782 seconds.
Elapsed time is 0.001075 seconds.
Elapsed time is 0.001025 seconds.
Elapsed time is 0.001191 seconds.
compared to almost 100 ms in R2021a:
Elapsed time is 0.009721 seconds.
Elapsed time is 0.008442 seconds.
Elapsed time is 0.008579 seconds.
Elapsed time is 0.010353 seconds.
Elapsed time is 0.008737 seconds.
This affects both Linux and Windows machines.
In most cases it is advisible to create the object only once and reuse it within the loop.
While this works fine for simple scripts, this approach makes code much more error prone, when used with more complex message types (think of trajectory_msgs/JointTrajectory for example), where the length of the JointTrajectoryPoint array might vary.
Does something like "msg.reset()" exist that would reset all message properties before one reuses the object?