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

Rewrite native thread-local storage #116123

Merged
merged 2 commits into from
May 23, 2024
Merged

Conversation

joboet
Copy link
Member

@joboet joboet commented Sep 24, 2023

(part of #110897)

The current native thread-local storage implementation has become quite messy, uses indescriptive names and unnecessarily adds code to the macro expansion. This PR tries to fix that by using a new implementation that also allows more layout optimizations and potentially increases performance by eliminating unnecessary TLS accesses.

This does not change the recursive initialization behaviour I described in this comment, so it should be a library-only change. Changing that behaviour should be quite easy now, however.

r? @m-ou-se
@rustbot label +T-libs

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 24, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@joboet
Copy link
Member Author

joboet commented Nov 24, 2023

@rustbot author
until I fix CI.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 24, 2023
@joboet joboet marked this pull request as draft November 24, 2023 12:34
Comment on lines 100 to 102
fn __init() -> $t {
$init
}
Copy link
Contributor

@m-rph m-rph Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been impl'ing a lint in clippy to suggest const if possible, and it relies on this structure existing and returning exactly $init. As long as this doesn't change, the lint should keep working.

rust-lang/rust-clippy#12015

@bors
Copy link
Contributor

bors commented Jan 13, 2024

☔ The latest upstream changes (presumably #117285) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@joboet any updates on this? thanks

@joboet
Copy link
Member Author

joboet commented Feb 15, 2024

@rustbot label +S-blocked

I want to do some other cleanups before this can be merged.

@rustbot rustbot added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Feb 15, 2024
@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Mar 12, 2024
@joboet joboet marked this pull request as ready for review March 12, 2024 13:04
@joboet
Copy link
Member Author

joboet commented Mar 12, 2024

@rustbot ready

The other improvements proposed by #110897 become much easier once this is merged, so I'm prioritising this one again.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Mar 12, 2024
@rust-log-analyzer

This comment has been minimized.

@joboet
Copy link
Member Author

joboet commented Mar 16, 2024

I'm curious as to whether this affects performance. This should reduce the number of TLS accesses, after all.
@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 Mar 16, 2024
@bors
Copy link
Contributor

bors commented Apr 27, 2024

☔ The latest upstream changes (presumably #124428) made this pull request unmergeable. Please resolve the merge conflicts.

@m-ou-se
Copy link
Member

m-ou-se commented May 23, 2024

Thanks for working on this! This looks great.

Given that the average performance has improved, I'd say that the regressions are worth it. What do you think, @m-ou-se?

Agreed!

r=me after rebasing

@bors

This comment has been minimized.

@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 May 23, 2024
@joboet
Copy link
Member Author

joboet commented May 23, 2024

@bors r-
@bors r=m-ou-se
Whoops!

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 23, 2024
@bors
Copy link
Contributor

bors commented May 23, 2024

📌 Commit 60bf1ab has been approved by m-ou-se

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 23, 2024
@m-rph
Copy link
Contributor

m-rph commented May 23, 2024

I haven't checked the code, but does the clippy lint work?

@joboet
Copy link
Member Author

joboet commented May 23, 2024

I haven't checked the code, but does the clippy lint work?

Yes, it should work.

@m-rph
Copy link
Contributor

m-rph commented May 23, 2024

Splendid, thank you very much!

@bors
Copy link
Contributor

bors commented May 23, 2024

⌛ Testing commit 60bf1ab with merge 9c8a58f...

@bors
Copy link
Contributor

bors commented May 23, 2024

☀️ Test successful - checks-actions
Approved by: m-ou-se
Pushing 9c8a58f to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 23, 2024
@bors bors merged commit 9c8a58f into rust-lang:master May 23, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 23, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9c8a58f): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.4% [0.2%, 1.2%] 10
Regressions ❌
(secondary)
1.0% [0.7%, 1.6%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [0.2%, 1.2%] 10

Max RSS (memory usage)

Results (primary 6.9%, secondary 3.7%)

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)
10.4% [4.8%, 16.5%] 3
Regressions ❌
(secondary)
3.7% [3.5%, 3.9%] 2
Improvements ✅
(primary)
-3.4% [-3.4%, -3.4%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 6.9% [-3.4%, 16.5%] 4

Cycles

Results (primary 2.9%, secondary 3.2%)

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)
2.9% [1.6%, 4.1%] 2
Regressions ❌
(secondary)
3.2% [2.9%, 3.5%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.9% [1.6%, 4.1%] 2

Binary size

Results (primary 0.1%, secondary 0.1%)

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.3% [0.0%, 0.7%] 34
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 38
Improvements ✅
(primary)
-0.2% [-1.0%, -0.0%] 20
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-1.0%, 0.7%] 54

Bootstrap: 673.262s -> 673.733s (0.07%)
Artifact size: 315.60 MiB -> 315.79 MiB (0.06%)

@Mark-Simulacrum Mark-Simulacrum added the perf-regression-triaged The performance regression has been triaged. label May 27, 2024
@workingjubilee workingjubilee modified the milestones: 1.80.0, 1.79.0 Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.