Migrate from hashglobe to hashbrown for Rust fallible heap allocation
Categories
(Core :: CSS Parsing and Computation, task)
Tracking
()
Tracking | Status | |
---|---|---|
firefox77 | --- | fixed |
People
(Reporter: SimonSapin, Assigned: SimonSapin)
References
Details
Attachments
(4 files)
Rust APIs are said to have "fallible allocation" when they return an error instead of panicking/aborting when heap memory allocation fails (such as malloc
returning null
). std::collections::HashMap
has a try_reserve
method, but it’s not available on the Rust Stable release channel yet: https://github.com/rust-lang/rust/issues/48043
hashglobe
is a fork of an old version of that HashMap
that allows Stylo to use try_reserve
(and adds some more fallible APIs like try_entry
).
Since then, the internals of std::collections::HashMap
have been entirely replaced by a different implementation which is also available on crates.io as hashbrown
. Hashbrown has a try_reserve
method available on Rust Stable. This is not a problem since, unlike the standard library, Hashbrown can afford to make breaking changes by picking a next version number that Cargo considers incompatible.
We should consider switching Stylo to use Hashbrown, and then remove Hashglobe:
- This would remove the need to maintain a hash map implementation. Hashbrown is likely better maintained since it is used in the Rust standard library
- The standard library change was motivated by Hashbrown often being faster. Perhaps Stylo’s preformance can benefit as well
Assignee | ||
Comment 1•5 years ago
|
||
Manish, could you say more about this 'static
bound? Why is it needed? What’s the relationship with NonZero
? Is it fine to remove it if the compiler is still happy?
// FIXME(Manishearth) the 'static bound can be removed when
// our HashMap fork (hashglobe) is able to use NonZero,
// or when stdlib gets fallible collections
impl<T: 'static> SelectorMap<T> {
Comment 2•5 years ago
|
||
(In reply to Simon Sapin (:SimonSapin) from comment #1)
Manish, could you say more about this
'static
bound? Why is it needed? What’s the relationship withNonZero
? Is it fine to remove it if the compiler is still happy?// FIXME(Manishearth) the 'static bound can be removed when // our HashMap fork (hashglobe) is able to use NonZero, // or when stdlib gets fallible collections impl<T: 'static> SelectorMap<T> {
I'm ~sure that's the case. HashGlobe
requires 'static
, but if hashbrown doesn't we should be alright.
Assignee | ||
Comment 3•5 years ago
|
||
This is the hash map implementation now used in the Rust standard library:
Assignee | ||
Comment 4•5 years ago
|
||
Assignee | ||
Comment 5•5 years ago
|
||
This works even if the Rust standard library’s allocator is not libc::malloc
,
so we can remove the known_system_malloc
feature flag
and make the fallible
crate unconditional.
Assignee | ||
Comment 6•5 years ago
|
||
Comment 7•5 years ago
|
||
(In reply to Simon Sapin (:SimonSapin) from comment #1)
Manish, could you say more about this
'static
bound? Why is it needed? What’s the relationship withNonZero
? Is it fine to remove it if the compiler is still happy?
It's because we used &'static T
to emulate NonZero<T>
. Totally fine to remove if the compiler is happy.
Assignee | ||
Comment 8•5 years ago
|
||
Comment 10•5 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/06dcf8ddbfde
https://hg.mozilla.org/mozilla-central/rev/de10216a9eb7
https://hg.mozilla.org/mozilla-central/rev/1d992cb96cca
https://hg.mozilla.org/mozilla-central/rev/d0ee684793c4
Comment 11•5 years ago
|
||
== Change summary for alert #25703 (as of Fri, 24 Apr 2020 11:03:22 GMT) ==
Improvements:
6% perf_reftest_singletons link-style-cache-1.html linux64-shippable-qr opt e10s stylo 714.43 -> 673.07
6% perf_reftest_singletons link-style-cache-1.html linux64-shippable-qr opt e10s stylo 713.14 -> 673.88
5% perf_reftest_singletons link-style-cache-1.html linux64-shippable opt e10s stylo 690.35 -> 652.55
For up to date results, see: https://treeherder.mozilla.org/perf.html#/alerts?id=25703
Comment 12•4 years ago
|
||
== Change summary for alert #26277 (as of Fri, 19 Jun 2020 05:30:43 GMT) ==
Improvements:
4% Images windows10-64-shippable-qr opt tp6 10,653,356.15 -> 10,241,364.96
4% Images linux1804-64-shippable opt tp6 8,918,652.07 -> 8,575,068.06
3% Images linux1804-64-shippable-qr opt tp6 8,883,869.78 -> 8,598,540.02
3% Images macosx1014-64-shippable opt tp6 9,961,281.38 -> 9,658,324.02
For up to date results, see: https://treeherder.mozilla.org/perf.html#/alerts?id=26277
Description
•