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

Emit the enum discriminant separately for the Encodable macro #108440

Merged
merged 1 commit into from
Feb 27, 2023

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Feb 25, 2023

This changes the Encodable proc macro to first emit the discriminant with a separate match statement, then emit the fields. LLVM can optimize down the first match to just a read of the enum discriminant. This avoids generating a emit_usize call per variant and enums with no fields now optimize down to just a single emit_usize call.

The no variant case is special cased to avoid warnings about unreachable code.

BenchmarkBeforeAfter
TimeTime%
🟣 clap:check:unchanged0.4676s0.4640s -0.78%
🟣 hyper:check:unchanged0.1348s0.1338s -0.75%
🟣 regex:check:unchanged0.3370s0.3352s -0.54%
🟣 syn:check:unchanged0.6326s0.6281s -0.71%
🟣 syntex_syntax:check:unchanged1.8561s1.8589s 0.15%
Total3.4282s3.4200s -0.24%
Summary1.0000s0.9947s -0.53%

@rustbot
Copy link
Collaborator

rustbot commented Feb 25, 2023

r? @TaKO8Ki

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2023
@cjgillot
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 25, 2023
@bors
Copy link
Contributor

bors commented Feb 25, 2023

⌛ Trying commit 7de205e with merge 57130c81008993e359d706fbf762508fdcbaaf69...

@bors
Copy link
Contributor

bors commented Feb 25, 2023

☀️ Try build successful - checks-actions
Build commit: 57130c81008993e359d706fbf762508fdcbaaf69 (57130c81008993e359d706fbf762508fdcbaaf69)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (57130c81008993e359d706fbf762508fdcbaaf69): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.6% [-1.0%, -0.3%] 89
Improvements ✅
(secondary)
-0.6% [-0.9%, -0.3%] 23
All ❌✅ (primary) -0.6% [-1.0%, -0.3%] 89

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.1% [3.1%, 3.1%] 1
Regressions ❌
(secondary)
3.4% [3.4%, 3.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.1% [3.1%, 3.1%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 25, 2023
@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 26, 2023

📌 Commit 7de205e has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 26, 2023
@bors
Copy link
Contributor

bors commented Feb 26, 2023

⌛ Testing commit 7de205e with merge 58136ff...

@bors
Copy link
Contributor

bors commented Feb 27, 2023

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 58136ff to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 27, 2023
@bors bors merged commit 58136ff into rust-lang:master Feb 27, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 27, 2023
@Zoxc Zoxc deleted the encoder-enum branch February 27, 2023 01:00
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (58136ff): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.6% [-1.0%, -0.3%] 91
Improvements ✅
(secondary)
-0.6% [-0.9%, -0.4%] 22
All ❌✅ (primary) -0.6% [-1.0%, -0.3%] 91

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.0% [-3.4%, -2.7%] 2
Improvements ✅
(secondary)
-2.9% [-4.5%, -1.3%] 2
All ❌✅ (primary) -3.0% [-3.4%, -2.7%] 2

Cycles

This benchmark run did not return any relevant results for this metric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants