perf: read header.stamp directly from CDR bytes without deserialization#89
Merged
perf: read header.stamp directly from CDR bytes without deserialization#89
Conversation
Replace full message deserialization in extract_header_stamp() with direct CDR byte reads at fixed offsets. All types in kTypesWithHeader have std_msgs/msg/Header as their first field, so stamp.sec (offset 4) and stamp.nanosec (offset 8) can be read via memcpy. This eliminates heap allocation and data copying for every message when --use-header-stamp-as-log-time is enabled. The impact is especially significant for large messages like sensor_msgs/msg/Image, where megabytes of pixel data were previously deserialized just to read 8 bytes of timestamp. Also removes 18 ROS message type includes and template instantiations from header_stamp.cpp, reducing compile time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extract_header_stamp()with direct CDR byte reads at fixed offsets (4-11)kTypesWithHeaderhavestd_msgs/msg/Headeras their first field, sostamp.secandstamp.nanosecare at known CDR offsetsheader_stamp.cppBefore
Every message was fully deserialized to read 8 bytes of timestamp. For
sensor_msgs/msg/Image(multi-MB), this allocated and copied the entire pixel buffer.After
Two
memcpycalls readsecandnanosecdirectly from the serialized buffer. Zero heap allocation, zero data copying.Test plan
colcon build)--use-header-stamp-as-log-timeand verify output timestamps match previous behavior--use-header-stamp-as-log-time(code path not reached)