BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Rust 1.7 Brings 2x Faster Hashes and New Stable APIs

Rust 1.7 Brings 2x Faster Hashes and New Stable APIs

After to stabilizing libcore in version 1.6, recently announced Rust 1.7 brings improvements and stability to about 40 library functions and methods. Additionally, Rust package manager Cargo got two new features for better dependency handling.

The single most important change brought by Rust 1.7 is support for custom hash algorithms with the standard library’s HashMap<K, V> type and their implicit selection based on type inference. In particular, Rust will now use a new FNV hashing algorithm for hashes that use small keys, such as HashMap<usize, V>. According to Rust development team, this will provide a 2x boost in performance compared to small key hashs using the previously default SipHash algorithm, which is not very fast at hashing small keys. However, the new FNV hasher will not provide the same protection against DOS attacks as SipHash, so it is good to know that the default inferred hasher can be overridden by explicitly specifying the desired one when instantiating the hash:

type MyHasher = BuildHasherDefault<SipHasher>;
fn main() {
    let mut map: HashMap<_, _, MyHasher> = HashMap::default();
    ...
}

Other improvements brought by Rust 1.7 are:

  • <[T]>::clone_from_slice(), which provides an efficient way to copy the data from one slice into another slice;
  • a few convenience method to handle Ipv4Addr and Ipv6Addr;
  • various improvements to CString;
  • checked, saturated, and overflowing operations for various numeric types.

A few changes in Rust 1.7 break compatibility with previous versions, which should be appropriately taken into account before switching versions. However, Rust core team member Steve Klabnik stated that he sent in a number of fixes to many existing libraries, and in the vast majority of cases the fix was trivial. An additional detail about how the Rust team assesses the potential breaking impact of a change, was shared by Hacker News user kibwen, who explained that they use a tool, Crater, to try to compile all of the packages on crates.io and thus determine how many packages rely on unsound behaviour.

Finally, Rust 1.7 also includes the following improvements to Cargo:

  • build scripts can now precisely describe dependencies so they’re only rerun when those files change;
  • it is now possible to specify profiles to pull in specific dependencies during testing and in other scenarios.

You can read the release notes for a list of all changes in Rust 1.7.

Rate this Article

Adoption
Style

BT