zenoh icon indicating copy to clipboard operation
zenoh copied to clipboard

Performance issues with current "contiguous" implementation

Open kydos opened this issue 1 year ago • 0 comments

The implementation for the contiguous operation is sub-optimal for the case in which we have multiple slices.

This code: https://github.com/eclipse-zenoh/zenoh/blob/7a4744576e21c85d31b1527b2c4bf2230e5152e8/commons/zenoh-buffers/src/lib.rs#L105

Should be rewritten to look something like:

_ => {
                    let mut l = 0;
                    for s in slices.by_ref() {
                        l += s.len();
                    }
                    let mut vec = Vec::with_capacity(l);
                    for slice in slices {
                        vec.extend_from_slice(slice);
                    }
                    Cow::Owned(vec)
                },

This will ensure a single allocation and will reduce to the minimum the total number of bytes actually copied.

kydos avatar May 02 '24 21:05 kydos