Rc and Arc variant for persistent data-structure

I am building a persistent array using a variant of rope-data-structure.

The array is actually held in a tree and there is a choice of using Rc or Arc to hold child references. Rc is good for performance, but do not have Send and Sync, while Arc has Send and Sync but not as good as Rc in performance.

I don't want to repeat the entire implementation, one for Rc, and another for Arc. I don't know how best to handle this situation.

Take a look at how https://github.com/bodil/im-rs does this.

https://github.com/bodil/im-rs/blob/3f4e01a43254fe228d1ce64e47dfaf4edc8f4f19/build.rs#L15-L24

2 Likes

Actually I am bench-marking im::Vector. If I understand correctly, im and im-rc are two separate packages. Also there is some maintenance overhead in keeping Cargo.toml for both the package in sync. Looks like im is doing some smart scripting with Makefile.toml and release.toml. I am just hoping for a simpler solution.

They have mostly parallel APIs, so you should be able to get a long way with something like this:

pub mod atomic {
    use std::sync::Arc as Rc;
    use std::sync::Weak;

    #[path = "..."] mod common;
    pub use common::*;
}

pub mod unsynced {
    use std::rc::{Rc,Weak};

    #[path = "..."] mod common;
    pub use common::*;
}
2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.