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

Support Arc in addition to Rc and & #19

Open
zslayton opened this issue Nov 13, 2018 · 5 comments
Open

Support Arc in addition to Rc and & #19

zslayton opened this issue Nov 13, 2018 · 5 comments

Comments

@zslayton
Copy link
Owner

Pool values are currently neither Send nor Sync, which precludes some interesting use cases around rayon and crossbeam.

Add support for creating a Pool that emits Arc references once Generic Associated Types (rust-lang/rust/issues/44265) lands.

@chachi
Copy link

chachi commented Mar 13, 2019

Is there a reason (besides avoiding code duplication) that this feature is blocked on GATs landing?

@zslayton
Copy link
Owner Author

It's a combination of code duplication and lack of development time. I have a branch with a near-complete refactor somewhere that would minimize the duplication, but it changes the API somewhat so I've been waiting for the opportunity to collect some feedback before pulling the trigger. The change (described in this thread) would allow for the removal of virtual dispatch, make it easier to make a Pool of values for data types you don't own, and allow different pointer types under the hood.

In the meantime, if someone were to submit a PR adding support for Arc using code duplication (along with benchmarks/tests), I'd be happy to review it!

@orium
Copy link

orium commented Jun 16, 2019

You might want to take a look at archery. (Disclaimer: I'm the author 🙂)

@SethDusek
Copy link

I think being able to share the Pool itself across threads will also be nice too. Currently Pool is not Sync as it uses an Rc/RefCell internally.

@zslayton
Copy link
Owner Author

zslayton commented Aug 4, 2020

After some experimentation on a local branch, benchmarks show that using an Arc<Mutex<_>> or an Arc<RwLock<_>> instead of Rc<RefCell<_>> degrades performance to the point that just using the system allocator is a huge win.

This single-threaded benchmark simply allocated blank Strings in a tight loop:

test tests::allocation_standard     ... bench:   8,609,401 ns/iter (+/- 5,116,983) // System allocator
test tests::allocation_pooled       ... bench:   4,789,584 ns/iter (+/- 144,361)   // &RefCell<_>
test tests::allocation_pooled_rc    ... bench:   6,293,622 ns/iter (+/- 190,541)   // Rc<RefCell<_>>
test tests::allocation_pooled_sync  ... bench:  14,181,916 ns/iter (+/- 375,415)   // &RwLock<_>
test tests::allocation_pooled_arc   ... bench:  22,166,528 ns/iter (+/- 490,503)   // Arc<RwLock<_>>

Note that the Mutex and RwLock types being used here are from the parking_lot crate. Their equivalents in the standard library were much, much slower.

I'd still like to offer this feature, but I'll need to look into other concurrency strategies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants