Skip to content

arazabishov/pvec-rs

Repository files navigation

pvec-rs

GitHub Workflow Status Crates.io API

A persistent vector implementation based on RRB-Tree for Rust, inspired by the blog post of Niko Matsakis - In Rust, ordinary vectors are values. This project offers a general-purpose, persistent vector with good performance across all operations, including efficient clone, concatenation, and splitting.

One of the vector types - PVec, explores an idea of starting out as the standard vector and spills to the tree representation only when cloned to offer the best possible performance. The API of methods provided by pvec-rs is identical to the standard vector, reducing the friction of using the library. Another notable feature is the out of the box support for Rayon.

The performance evaluation of the library is provided in the technical report. PVec is available on crates.io, and API documentation is available on docs.rs.

Example

A demonstration of using PVec:

extern crate pvec;

use pvec::PVec;

fn example_pvec(size: usize) {
    let mut vec = PVec::new();
    // ^ backed by the standard vector internally

    for i in 0..size {
        vec.push(i);
    }

    let cln = vec.clone();
    // ^ transitions to RrbVec internally,
    // with consequent clones that cost O(1)

    let res: PVec<usize> = vec.into_par_iter()
        .map(|it| it + 1)
        .collect();
    // ^ processing vector in parallel and
    // collecting results
}

Benchmarks

Runtime

Runtime benchmarks are subdivided into sequential and parallel groups. The framework used to run benchmark is criterion, which can generate an HTML report with charts if you have gnuplot pre-installed.

# running all sequential benches
cargo bench

# running parallel benches
cargo bench --features=arc,rayon_iter

The report can be found at target/criterion/report/index.html. To avoid running benchmarks for hours, pass the --sample-size=10 option to reduce the sample count.

Results Benchmarks were executed against the library configured with Arc and Rc pointers. The results are available here: arc and rc.

Memory

Memory footprint is measured using a custom binary crate - benches-mem. This binary runs benchmarks from the benches crate through the time util, capturing the peak memory usage of the process. The report is placed at target/release/report. Note, these benchmarks can be executed only on macOS at the moment, as time behaves differently on mac and linux.

cd benches-mem && sh bench.sh

License

MIT License

Copyright (c) 2020 Araz Abishov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

A persistent, RRB-Tree based vector for Rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published