Skip to content

port from ~[T] to Vec<T> #11875

Closed
Closed
@thestinger

Description

@thestinger

Annoying issues, but not hard blockers:

This is a significant performance improvement for any vectors that are grown, and will reduce heap allocation since zero-length vectors do not allocate and it does not have a header.

test bench::old_push              ... bench:     43200 ns/iter (+/- 804)
test bench::old_push_preallocated ... bench:     42948 ns/iter (+/- 4043)
test bench::push                  ... bench:      7190 ns/iter (+/- 245)
test bench::push_preallocated     ... bench:      6606 ns/iter (+/- 170)
#[cfg(test)]
extern mod extra;

#[cfg(test)]
mod bench {
    use std;
    use std::vec_ng::Vec;
    use extra::test::BenchHarness;

    static size: uint = 10000;

    #[bench]
    fn push(bh: &mut BenchHarness) {
        bh.iter(|| {
            let mut xs = Vec::with_capacity(16);
            for i in range(0, size) {
                xs.push(i);
            }
        });
    }

    #[bench]
    fn old_push(bh: &mut BenchHarness) {
        bh.iter(|| {
            let mut xs = std::vec::with_capacity(16);
            for i in range(0, size) {
                xs.push(i);
            }
        });
    }

    #[bench]
    fn push_preallocated(bh: &mut BenchHarness) {
        bh.iter(|| {
            let mut xs = Vec::with_capacity(size);
            for i in range(0, size) {
                xs.push(i);
            }
        });
    }

    #[bench]
    fn old_push_preallocated(bh: &mut BenchHarness) {
        bh.iter(|| {
            let mut xs = std::vec::with_capacity(size);
            for i in range(0, size) {
                xs.push(i);
            }
        });
    }
}

I moved the priority tag here from the old issue, as this is the same core issue but without the distractions of past issues and discussions that are no longer relevant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions