BT

Rust 1.7 Brings 2x Faster Hashes and New Stable APIs

| by Sergio De Simone Follow 14 Followers on Mar 06, 2016. Estimated reading time: 1 minute |

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 Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT