Skip to content

derived Clone implementations for many-variant enums are unnecessarily large #47796

Open
@bholley

Description

@bholley

The derived Clone implementations in Firefox weigh 192k [1], which is a lot.

Of that 192k, 79k of that is just for PropertyDeclaration::clone. PropertyDeclaration is a very large enum, but most of the variants are simple POD types. Ideally Rust would coalesce those together, and then generate special cases for the types that need it. Unfortunately, it appears that adding a single non-POD variant causes all the cases to be enumerated separately, as seen in the testcase at [2].

From IRC:

eddyb bholley: yeah I think this is a valid issue
eddyb: if you do generate that sort of "(partial) identity match" it's unlikely to have anything else collapse it
eddyb: LLVM might have a pass for switch-discriminant-dependent-values
eddyb: but it probably has serious limitations in practice
eddyb: bholley: but yeah this is one of those cases where not scattering in the first place is significantly easier than gathering later`

Ideally we'd do the same for PartialEq, since PropertyDeclaration::eq weighs another 61k.

[1] nm --print-size --size-sort --radix=d libxul.so | grep "..Clone" | grep -v Cloned | cut -d " " -f 2 | awk '{s+=$1} END {print s}'
[2] https://play.rust-lang.org/?gist=0207af76d2e05acdbed913b7df96aa77&version=stable

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-heavyIssue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions