aboutsummaryrefslogtreecommitdiff
path: root/src/join.rs
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2021-02-28 20:52:23 -0500
committerJack O'Connor <[email protected]>2021-03-14 00:08:21 -0500
commitea72822620ba77e4f597bf6d6bd4bd8c3b4cc9dc (patch)
tree1f8497a7b0d2118a7385098f88c473e1864e3ccf /src/join.rs
parent71d67e081028972790d4b56e23dc57805aa78a85 (diff)
re-privatize the Join trait
Diffstat (limited to 'src/join.rs')
-rw-r--r--src/join.rs47
1 files changed, 9 insertions, 38 deletions
diff --git a/src/join.rs b/src/join.rs
index 60932db..2435bc6 100644
--- a/src/join.rs
+++ b/src/join.rs
@@ -8,47 +8,18 @@
//! [`hash`] and [`Hasher::update`], always use `SerialJoin` internally.
//!
//! The `Join` trait is an almost exact copy of the [`rayon::join`] API, and
-//! `RayonJoin` is the only non-trivial implementation provided. The only
-//! difference between the function signature in the `Join` trait and the
-//! underlying one in Rayon, is that the trait method includes two length
-//! parameters. This gives an implementation the option of e.g. setting a
-//! subtree size threshold below which it keeps splits on the same thread.
-//! However, neither of the two provided implementations currently makes use of
-//! those parameters. Note that in Rayon, the very first `join` call is more
-//! expensive than subsequent calls, because it moves work from the calling
-//! thread into the thread pool. That makes a coarse-grained input length
-//! threshold in the caller more effective than a fine-grained subtree size
-//! threshold after the implementation has already started recursing.
+//! `RayonJoin` is the only non-trivial implementation. Previously this trait
+//! was public, but currently it's been re-privatized, as it's both 1) of no
+//! value to most callers and 2) a pretty big implementation detail to commit
+//! to.
//!
-//! # Example
-//!
-//! ```
-//! // Hash a large input using multi-threading. Note that multi-threading
-//! // comes with some overhead, and it can actually hurt performance for small
-//! // inputs. The meaning of "small" varies, however, depending on the
-//! // platform and the number of threads. (On x86_64, the cutoff tends to be
-//! // around 128 KiB.) You should benchmark your own use case to see whether
-//! // multi-threading helps.
-//! # #[cfg(feature = "rayon")]
-//! # {
-//! # fn some_large_input() -> &'static [u8] { b"foo" }
-//! let input: &[u8] = some_large_input();
-//! let mut hasher = blake3::Hasher::new();
-//! hasher.update_with_join::<blake3::join::RayonJoin>(input);
-//! let hash = hasher.finalize();
-//! # }
-//! ```
-//!
-//! [`Hasher::update_with_join`]: ../struct.Hasher.html#method.update_with_join
-//! [`Hasher::update`]: ../struct.Hasher.html#method.update
-//! [`hash`]: ../fn.hash.html
//! [`rayon::join`]: https://docs.rs/rayon/1.3.0/rayon/fn.join.html
/// The trait that abstracts over single-threaded and multi-threaded recursion.
///
/// See the [`join` module docs](index.html) for more details.
pub trait Join {
- fn join<A, B, RA, RB>(oper_a: A, oper_b: B, len_a: usize, len_b: usize) -> (RA, RB)
+ fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
where
A: FnOnce() -> RA + Send,
B: FnOnce() -> RB + Send,
@@ -66,7 +37,7 @@ pub enum SerialJoin {}
impl Join for SerialJoin {
#[inline]
- fn join<A, B, RA, RB>(oper_a: A, oper_b: B, _len_a: usize, _len_b: usize) -> (RA, RB)
+ fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
where
A: FnOnce() -> RA + Send,
B: FnOnce() -> RB + Send,
@@ -88,7 +59,7 @@ pub enum RayonJoin {}
#[cfg(feature = "rayon")]
impl Join for RayonJoin {
#[inline]
- fn join<A, B, RA, RB>(oper_a: A, oper_b: B, _len_a: usize, _len_b: usize) -> (RA, RB)
+ fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
where
A: FnOnce() -> RA + Send,
B: FnOnce() -> RB + Send,
@@ -107,7 +78,7 @@ mod test {
fn test_serial_join() {
let oper_a = || 1 + 1;
let oper_b = || 2 + 2;
- assert_eq!((2, 4), SerialJoin::join(oper_a, oper_b, 3, 4));
+ assert_eq!((2, 4), SerialJoin::join(oper_a, oper_b));
}
#[test]
@@ -115,6 +86,6 @@ mod test {
fn test_rayon_join() {
let oper_a = || 1 + 1;
let oper_b = || 2 + 2;
- assert_eq!((2, 4), RayonJoin::join(oper_a, oper_b, 3, 4));
+ assert_eq!((2, 4), RayonJoin::join(oper_a, oper_b));
}
}