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

Conversation

dotdash
Copy link
Contributor

@dotdash dotdash commented May 12, 2016

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.

@rust-highfive
Copy link
Collaborator

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@brson
Copy link
Contributor

brson commented May 12, 2016

@bors r+

@bors
Copy link
Contributor

bors commented May 12, 2016

📌 Commit 3d651e6 has been approved by brson

…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
Copy link
Contributor Author

dotdash commented May 12, 2016

@bors r=brson

Fixed the tests.

@bors
Copy link
Contributor

bors commented May 12, 2016

📌 Commit 0eeb14e has been approved by brson

eddyb added a commit to eddyb/rust that referenced this pull request May 13, 2016
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.
@bors
Copy link
Contributor

bors commented May 14, 2016

⌛ Testing commit 0eeb14e with merge cdaa601...

@bors
Copy link
Contributor

bors commented May 15, 2016

💔 Test failed - auto-mac-32-opt

@arielb1
Copy link
Contributor

arielb1 commented May 15, 2016

random timeout

@bors retry

@bors
Copy link
Contributor

bors commented May 15, 2016

⌛ Testing commit 0eeb14e with merge 088d417...

bors added a commit that referenced this pull request May 15, 2016
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.
@bors bors merged commit 0eeb14e into rust-lang:master May 15, 2016
bors added a commit that referenced this pull request May 16, 2016
@dotdash dotdash deleted the smart_derive branch May 17, 2016 03:44
nox added a commit to servo/servo that referenced this pull request May 17, 2016
nox added a commit to servo/servo that referenced this pull request May 17, 2016
zakorgy pushed a commit to zakorgy/servo that referenced this pull request May 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants