In hashbrown
, we collect all the elements of the parallel iterator into a LinkedList
of Vec
and then we extend the map with each of those vecs. See:
Whereas in rayon
, there is a fast path for if the parallel iterator's opt_len
method returns a Some
(this happens with iterators over Vec
and slice
and such). See:
in that case, rayon will collect the values directly into that vec, without allocating N Vecs
and a LinkedList
: https://docs.rs/rayon/latest/src/rayon/iter/collect/mod.rs.html#23
Ideally hashbrown would either be able to implement this optimization itself, or somehow delegate to a public API in rayon to perform this optimization.