Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Initial implementation #1

Merged
3 commits merged into from Nov 26, 2017
Merged

Initial implementation #1

3 commits merged into from Nov 26, 2017

Conversation

ghost
Copy link

@ghost ghost commented Nov 5, 2017

This is the initial implementation, based upon the one in Coco, which was in turn based on the old implementation in Crossbeam and the deque crate.

Copy link
Contributor

@jeehoonkang jeehoonkang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll continue to read this PR later. I only read the documentation..

Cargo.toml Outdated

[dependencies]
crossbeam-epoch = { git = "https://github.com/stjepang/crossbeam-epoch", branch = "guard" }
crossbeam-utils = { git = "https://github.com/crossbeam-rs/crossbeam-utils" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We published crossbeam-utils in crates.io. What about using it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I should just publish a new version... The latest version was published a while ago.

//!
//! Of course, there are many variations of this strategy. For example, sometimes it may be
//! beneficial for a thread to always [`steal`][Deque::steal] work from the top of its deque
//! instead of calling [`pop`] and taking it from the bottom.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curious, what would be the benefit of using fn Deque::steal() instead of fn Deque::pop()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rayon uses steal instead of pop when in the "breadth-first" mode, which gives a pretty large speedup in Stylo. See rayon-rs/rayon#360 for more details.

//! d.push('b');
//! d.push('c');
//!
//! assert_eq!(d.pop(), Some('c'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other data structures, we named to popping function try_pop() instead of pop(). I don't have a strong opinion on what's better, but I'd like to have a consistent name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion either... It really depends. Here are some counterexamples:

  1. Vec::pop (not try_pop) returns an Option<T>.
  2. HashMap::remove (not try_remove) returns an Option<V>.
  3. LinkedList::pop_front (not try_pop_front) returns an Option<T>.
  4. BinaryHeap::pop (not try_pop) returns an Option<T>.
  5. String::pop (not try_pop) returns an Option<char>.

Copy link
Contributor

@jeehoonkang jeehoonkang Nov 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I prefer pop. Let's use this name for queues and other data structures :)

Copy link
Contributor

@jeehoonkang jeehoonkang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have several comments on the implementation, but I'd like to merge it as-is as the initial version of crossbeam-deque, because (a slight variation of) this implementation in coco works for rayon and other projects.

Here are some changes I'd like to propose later:

  • interface: I want to expose a deque that uses the Handle interface rather than using epoch::pin(), because now Handle is one of our first-class API. Of course, we need to expose deque using epoch::pin() for the majority of use cases.

  • optimization: e.g. I think it's not necessary to swap the buffer when resizing. Actually I'm proving it (https://github.com/jeehoonkang/crossbeam-rfcs/blob/deque/text/2017-08-30-deque.md), but it's not done yet (even after 3 months!). I'm proposing this RFC with a corresponding PR to this repo.

//! d.push('b');
//! d.push('c');
//!
//! assert_eq!(d.pop(), Some('c'));
Copy link
Contributor

@jeehoonkang jeehoonkang Nov 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I prefer pop. Let's use this name for queues and other data structures :)

@ghost ghost merged commit d5dd2a8 into crossbeam-rs:master Nov 26, 2017
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant