Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seed HashMaps thread-locally, straight from the OS. #31356

Closed
wants to merge 1 commit into from

Commits on Feb 2, 2016

  1. Seed HashMaps thread-locally, straight from the OS.

    This reduces how much rand is required in std, and makes creating
    hash-maps noticably faster. The first invocation of HashMap::new() in a
    thread goes from ~130_000 ns to ~1500 ns (i.e. 86x faster) and later
    invocations go from 10-20 ns to a more consistent 1.8-2.0ns.
    
    The mean for many invocations in a loop, on a single thread, goes from
    ~77ns to ~1.9ns, and the standard deviation drops from 2800ns to
    33ns (the *massive* variance of the old scheme comes from the occasional
    reseeding of the thread rng).
    
    These new numbers are only slightly higher than creating the
    `RandomState` outside the loop and calling `with_state` in it (i.e.
    only measuring the non-random parts of hashmap initialisation): 1.3 and
    18 ns respectively.
    
    This new scheme has the slight downside of being consistent on a single
    thread, so users may unintentionally rely on the order being
    fixed (e.g. two hashmaps with the same contents).
    
    Closes rust-lang#27243.
    huonw committed Feb 2, 2016
    Configuration menu
    Copy the full SHA
    3f84916 View commit details
    Browse the repository at this point in the history