Skip to content

par_extend for hashbrown's HashMap is less efficient than rayon's implementation for stdlib HashMap with par_iter over a Vec #651

@gaynor-anthropic

Description

@gaynor-anthropic

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions