Description
Commits 6a58537 / 760b93a (Thu May 29 19:03:06) introduced a performance regression in std::collections::HashMap insertion. The regression appears to be isolated to instances where the key is a string, but I have only tested with string and integer keys.
I have set up a test benchmark at https://github.com/SergioBenitez/rust-perf-regression that showcases the issue. It inserts 100 string/int key/value pairs into a HashMap. good.sh
runs the benchmark using the last good compiler build, 3ec321f, and bad.sh
runs the first bad compiler build, 760b93a, assuming rustc from 3ec321f is in /usr/local/good/bin/rustc
and rustc from 760b93a is in the current $PATH
.
Here are the results on my machine (Core i7-920, 24GB RAM, OS X 10.9.2):
$ ./good.sh (--opt-level=3 test.rs --cfg=good --test -o test.out)
test insert_100 ... bench: 7770 ns/iter (+/- 1294)
$ ./bad.sh (--opt-level=3 test.rs --cfg=bad --test -o test.out)
test insert_100 ... bench: 9443 ns/iter (+/- 1742)
@cmr on IRC suggested adding -Z lto. Here are the results with that flag:
$ ./good.sh (-Z lto --opt-level=3 test.rs --cfg=good --test -o test.out)
test insert_100 ... bench: 7148 ns/iter (+/- 1912)
$ ./bad.sh (-Z lto --opt-level=3 test.rs --cfg=bad --test -o test.out)
test insert_100 ... bench: 9066 ns/iter (+/- 1771)
As can be seen, the binary built from the compiler at 760b93a is about 25% slower than the binary from the compiler at 3ec321f.