Skip to content

HashSet::new() and HashMap::new() are enormously slow in the presence of the Tokio or Rayon runtime #94

@4r33x

Description

@4r33x

This code:

fn main() {
    let rt = tokio::runtime::Builder::new_multi_thread().enable_all().worker_threads(32).build().unwrap();
    let now = std::time::Instant::now();
    let set: papaya::HashSet<u32> = papaya::HashSet::new();
    println!("Papaya set build time: {:?}", now.elapsed());
    let p = set.pin_owned();
    std::thread::scope(|x| {
        p.len();
    });
}

Cargo.toml:

[package]
name = "papaya_test"
version = "0.1.0"
edition = "2024"

[dependencies]
papaya = "0.2.4"
tokio = { version = "1.51", features = ["full"] }

Prints:

    Finished `release` profile [optimized] target(s) in 2.63s
Papaya set build time: 22.005689ms

When tokio rt line commented out:

    Finished `release` profile [optimized] target(s) in 2.12s
Papaya set build time: 74.486µs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions