Closed peci1 closed 4 years ago
Here's my rationale from a node that processes lots of laserscans which are quite fresh so they often need some time before their transform gets into the cache.
This is a flamegraph where I circled all calls to createExtrapolationException*
. Roughly estimated, these calls take about 20% run time of my code. With this PR, it could be less than 10%.
Merging #469 could help a bit with this as most of the internal canTransform()
calls will no longer create the strings, but it still seems to me that people would profit from this further optimization.
Manually rebased and merged in 52bff88ecad8821802ad5e04dcb711b582c39f5a
For some reason, the stringstream construction of tf2 exception messages is much slower than snprintf().
In some cases, there may be lots of these messages generated, thus I think it makes sense to save time here.
A simple substitution of the stringstream approach with snprintf brings a two- to three-fold speedup for the error cases.
Speed test with the additions from #469 (the updated speed_test is not included in this PR, but I used it to measure the performance gain):
noetic-devel:
This patch:
There's one change that might be reverted if needed - the removal if
<sstream>
include from time_cache.h. It was just no longer needed for tf2, so I removed it, but if you think it'd be an API break, it can be put back.There should also be discussion on the string length limit in buffer_core. I chose 1000. Whatever else can be used. I also tried a solution with dynamic allocation of memory for the string, but it looked ugly (but the performance was nearly the same).