Commit 74b43aa
authored
perf(generator): use memcpy paths for primitive sequence conversion (#26)
For UnboundedSequence<BasicType> fields, route both conversion
directions through single-memcpy paths instead of element-by-element
loops.
- from_rmw_message: emit msg.field.into() instead of
msg.field.into_iter().collect(). Routes through rosidl_runtime_rs'
Copy-bounded From<Sequence<T>> for Vec<T> -> as_slice().to_vec() ->
memcpy. The old path paid a per-element read + zero-write through
SequenceIterator::next().
- into_rmw_message Owned arm: emit msg.field.as_slice().into() instead
of msg.field.into(). Routes through From<&[T]> for Sequence<T> ->
Sequence::new + clone_from_slice -> memcpy (stdlib specializes
clone_from_slice for T: Copy). The old path went through
From<Vec<T>> -> from_iter -> extend, paying a per-element IndexMut
write.
The Borrowed arm of into_rmw_message already used as_slice().into() and
is unchanged. Non-primitive element types (String, WString, nested
messages) still use .into_iter().map(...).collect() -- they need real
per-element conversion regardless.
Also restructures the from_rmw_message UnboundedSequence branch so each
element-type arm emits a single complete expression rather than sharing
a chained .into_iter()...collect() across arms.
Microbenchmarks (Sequence<u8> 65536 <-> Vec<u8>):
receive: 23.3 us -> 513 ns (45.4x)
publish: 28.3 us -> 726 ns (39.0x)
End-to-end (UInt8MultiArray, single-process, reliable QoS,
rmw_fastrtps_cpp, 64 KiB, median of 3 x 5s):
rclrs (main): 30,578 msg/s
rclrs (this branch): 135,560 msg/s (4.4x over main, ~90% of rclcpp)
rclcpp baseline: 151,279 msg/s
rclrs + Worker sub: 224,576 msg/s (~1.48x of rclcpp single-process)
Requires rosidl_runtime_rs with the new Copy-bounded
From<Sequence<T>> for Vec<T> impl (companion PR).
Refs ros2-rust/ros2_rust#628 improvement (1).1 parent 3cd60da commit 74b43aa
1 file changed
Lines changed: 19 additions & 3 deletions
Lines changed: 19 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
142 | 146 | | |
143 | | - | |
| 147 | + | |
144 | 148 | | |
145 | 149 | | |
146 | 150 | | |
| |||
243 | 247 | | |
244 | 248 | | |
245 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
246 | 256 | | |
247 | 257 | | |
248 | | - | |
249 | 258 | | |
| 259 | + | |
250 | 260 | | |
| 261 | + | |
| 262 | + | |
251 | 263 | | |
252 | | - | |
253 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
254 | 270 | | |
255 | 271 | | |
256 | 272 | | |
| |||
0 commit comments