]> git.lizzy.rs Git - rust.git/commit
Improve derived implementations for enums with lots of fieldless variants
authorBjörn Steinbrink <bsteinbr@gmail.com>
Thu, 12 May 2016 15:54:05 +0000 (17:54 +0200)
committerBjörn Steinbrink <bsteinbr@gmail.com>
Thu, 12 May 2016 19:05:13 +0000 (21:05 +0200)
commit0eeb14eaba04025aa8a4612e1935f04f2ca3fb6b
tree410400c6c9e7f7dd6fb098f1fd0d53dfbbe5dd04
parentc0495417416c8e0687bc6a997507c403627f6568
Improve derived implementations for enums with lots of fieldless variants

A number of trait methods like PartialEq::eq or Hash::hash don't
actually need a distinct arm for each variant, because the code within
the arm only depends on the number and types of the fields in the
variants. We can easily exploit this fact to create less and better
code for enums with multiple variants that have no fields at all, the
extreme case being C-like enums.

For nickel.rs and its by now infamous 800 variant enum, this reduces
optimized compile times by 25% and non-optimized compile times by 40%.
Also peak memory usage is down by almost 40% (310MB down to 190MB).

To be fair, most other crates don't benefit nearly as much, because
they don't have as huge enums. The crates in the Rust distribution that
I measured saw basically no change in compile times (I only tried
optimized builds) and only 1-2% reduction in peak memory usage.
13 files changed:
src/libsyntax_ext/deriving/clone.rs
src/libsyntax_ext/deriving/cmp/eq.rs
src/libsyntax_ext/deriving/cmp/ord.rs
src/libsyntax_ext/deriving/cmp/partial_eq.rs
src/libsyntax_ext/deriving/cmp/partial_ord.rs
src/libsyntax_ext/deriving/debug.rs
src/libsyntax_ext/deriving/decodable.rs
src/libsyntax_ext/deriving/default.rs
src/libsyntax_ext/deriving/encodable.rs
src/libsyntax_ext/deriving/generic/mod.rs
src/libsyntax_ext/deriving/hash.rs
src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin.rs
src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin_attr.rs