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

Reduce code size of thread::set_current #123356

Merged
merged 3 commits into from
May 4, 2024
Merged

Conversation

joboet
Copy link
Member

@joboet joboet commented Apr 2, 2024

#123265 introduced a rather large binary size regression, because it added an unwrap() call on a Result<(), Thread>, which in turn pulled its rather heavy Debug implementation. This PR fixes this by readding the rtassert! that was removed.

@rustbot
Copy link
Collaborator

rustbot commented Apr 2, 2024

r? @ChrisDenton

rustbot has assigned @ChrisDenton.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Apr 2, 2024
@Kobzol
Copy link
Contributor

Kobzol commented Apr 2, 2024

@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 Apr 2, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2024
Reduce code size of `thread::set_current`

rust-lang#123265 introduced a rather large binary size regression, because it added an `unwrap()` call on a `Result<(), Thread>`, which in turn pulled its rather heavy `Debug` implementation. This PR fixes this by readding the `rtassert!` that was removed.
@bors
Copy link
Contributor

bors commented Apr 2, 2024

⌛ Trying commit b5ccebf with merge ae182b1...

@Noratrieb
Copy link
Member

I think the push cancelled the try build.
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2024
Reduce code size of `thread::set_current`

rust-lang#123265 introduced a rather large binary size regression, because it added an `unwrap()` call on a `Result<(), Thread>`, which in turn pulled its rather heavy `Debug` implementation. This PR fixes this by readding the `rtassert!` that was removed.
@bors
Copy link
Contributor

bors commented Apr 2, 2024

⌛ Trying commit e7b5730 with merge c38c6c9...

@bors
Copy link
Contributor

bors commented Apr 2, 2024

☀️ Try build successful - checks-actions
Build commit: c38c6c9 (c38c6c92fe6cc168e48deb51b39da5367f0b340e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c38c6c9): comparison URL.

Overall result: ❌ regressions - 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)
3.3% [3.3%, 3.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

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

Cycles

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

Binary size

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)
-0.1% [-0.2%, -0.0%] 12
Improvements ✅
(secondary)
-0.9% [-1.3%, -0.2%] 39
All ❌✅ (primary) -0.1% [-0.2%, -0.0%] 12

Bootstrap: 666.146s -> 668.198s (0.31%)
Artifact size: 315.65 MiB -> 315.74 MiB (0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 2, 2024
@workingjubilee
Copy link
Member

That is ~exactly the number of things buffed as were regressed, and by about as much. Seems to patch the original completely. Nice work!

@bors r+

@bors
Copy link
Contributor

bors commented Apr 2, 2024

📌 Commit e7b5730 has been approved by workingjubilee

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 Apr 2, 2024
@workingjubilee
Copy link
Member

Wait.

@bors r-

@joboet Can you add a comment noting the use of rtabort! is load-bearing for about 5kb all on its lonesome?

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

joboet commented Apr 3, 2024

Sure, done!

@bors r=workingjubilee

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

joboet commented Apr 4, 2024

@bors r-
If some code running pre-main accesses thread::current, this will abort because the thread will be initialized before we get a chance to do so in init.

@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 Apr 4, 2024
@RalfJung
Copy link
Member

RalfJung commented Apr 4, 2024

That just means pre-main code should not do that...?
We control all pre-main code.

@joboet
Copy link
Member Author

joboet commented Apr 4, 2024

No, there are ways and means to get around that. We document our limitations here, thread::current before main isn't on the list. And considering how simple it is to support that, I don't see why we shouldn't. I've changed the abort to a noop now.

@RalfJung
Copy link
Member

RalfJung commented Apr 4, 2024

Silently dropping this seems rather suspicious but I don't have any overview over the lifecycle of this variable.

@joboet
Copy link
Member Author

joboet commented Apr 4, 2024

We normally call this in rt::init and the thread main function. For threads, nothing can run before it that we don't control, but for main you could use some linker magic. If you then access thread::current, it gets initialized to some default value (so that it can be used in foreign threads), meaning that the set_current in rt::init will abort.

Anyway, I don't feel any particular way about this, as long as we don't unwrap on a Result<(), Thread>, because that leads to the code size issues this PR aimed to solve.

@RalfJung
Copy link
Member

RalfJung commented Apr 4, 2024

If you then access thread::current, it gets initialized to some default value (so that it can be used in foreign threads), meaning that the set_current in rt::init will abort.

What's the consequence of discarding it the 2nd time? Just a different thread name or anything more serious?

If you change it like this IMO it should be called try_set_current or so.

@workingjubilee
Copy link
Member

💀 what

@joboet
Copy link
Member Author

joboet commented Apr 8, 2024

Sorry for the confusion, I totally derailed the conversation. The PR is now back to the approved state, with an updated abort message as Ralf suggested.
@rustbot ready

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 8, 2024
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 8, 2024
@ChrisDenton
Copy link
Member

Sorry for the confusion, I totally derailed the conversation. The PR is now back to the approved state, with an updated abort message as Ralf suggested.

lgtm

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 4, 2024

📌 Commit 37c1758 has been approved by ChrisDenton

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 May 4, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 4, 2024
…nton

Reduce code size of `thread::set_current`

rust-lang#123265 introduced a rather large binary size regression, because it added an `unwrap()` call on a `Result<(), Thread>`, which in turn pulled its rather heavy `Debug` implementation. This PR fixes this by readding the `rtassert!` that was removed.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#123356 (Reduce code size of `thread::set_current`)
 - rust-lang#124159 (Move thread parking to `sys::sync`)
 - rust-lang#124293 (Let miri and const eval execute intrinsics' fallback bodies)
 - rust-lang#124500 (lldb-formatters: Use StdSliceSyntheticProvider for &str)
 - rust-lang#124677 (Set non-leaf frame pointers on Fuchsia targets)
 - rust-lang#124692 (We do not coerce `&mut &mut T -> *mut mut T`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#123356 (Reduce code size of `thread::set_current`)
 - rust-lang#124159 (Move thread parking to `sys::sync`)
 - rust-lang#124293 (Let miri and const eval execute intrinsics' fallback bodies)
 - rust-lang#124677 (Set non-leaf frame pointers on Fuchsia targets)
 - rust-lang#124692 (We do not coerce `&mut &mut T -> *mut mut T`)
 - rust-lang#124698 (Rewrite `rustdoc-determinism` test in Rust)
 - rust-lang#124700 (Remove an unnecessary cast)
 - rust-lang#124701 (Docs: suggest `uN::checked_sub` instead of check-then-unchecked)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b8fa047 into rust-lang:master May 4, 2024
11 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 4, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2024
Rollup merge of rust-lang#123356 - joboet:set_current_size, r=ChrisDenton

Reduce code size of `thread::set_current`

rust-lang#123265 introduced a rather large binary size regression, because it added an `unwrap()` call on a `Result<(), Thread>`, which in turn pulled its rather heavy `Debug` implementation. This PR fixes this by readding the `rtassert!` that was removed.
@joboet joboet deleted the set_current_size branch May 4, 2024 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

10 participants