Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issues with current "contiguous" implementation #1008

Closed
kydos opened this issue May 2, 2024 · 1 comment
Closed

Performance issues with current "contiguous" implementation #1008

kydos opened this issue May 2, 2024 · 1 comment
Labels
enhancement Existing things could work better

Comments

@kydos
Copy link
Member

kydos commented May 2, 2024

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

This code:

_ => Cow::Owned(slices.fold(Vec::new(), |mut acc, it| {

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 kydos added the enhancement Existing things could work better label May 2, 2024
kydos added a commit to kydos/zenoh that referenced this issue May 2, 2024
kydos added a commit to kydos/zenoh that referenced this issue May 3, 2024
Mallets added a commit that referenced this issue May 4, 2024
* Fixed performance issue with contiguous (#1008)

* fixed format issue slipped in when fixing (#1008)

* Update commons/zenoh-buffers/src/lib.rs

Co-authored-by: Luca Cominardi <luca.cominardi@gmail.com>

---------

Co-authored-by: Luca Cominardi <luca.cominardi@gmail.com>
YuanYuYuan pushed a commit to ZettaScaleLabs/zenoh that referenced this issue May 6, 2024
…-zenoh#1009)

* Fixed performance issue with contiguous (eclipse-zenoh#1008)

* fixed format issue slipped in when fixing (eclipse-zenoh#1008)

* Update commons/zenoh-buffers/src/lib.rs

Co-authored-by: Luca Cominardi <luca.cominardi@gmail.com>

---------

Co-authored-by: Luca Cominardi <luca.cominardi@gmail.com>
@YuanYuYuan
Copy link
Contributor

Has been completed via #1009 and #1022.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Existing things could work better
Projects
None yet
Development

No branches or pull requests

3 participants