Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve derived implementations for enums with lots of fieldless variants #33593

Merged
merged 1 commit into from
May 15, 2016

Commits on May 12, 2016

  1. Improve derived implementations for enums with lots of fieldless vari…

    …ants
    
    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.
    dotdash committed May 12, 2016
    Configuration menu
    Copy the full SHA
    0eeb14e View commit details
    Browse the repository at this point in the history