Skip to content

refactor Lock for parallel compiler #109467

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

Closed
wants to merge 1 commit into from

Conversation

SparrowLii
Copy link
Member

@SparrowLii SparrowLii commented Mar 22, 2023

part of #101566
This PR refactor Lock for parallel compiler, facilitating code review and perf test.

ps. refactored Lock is not Send or Sync. It depends on #107586 to get thread safety.

@rustbot
Copy link
Collaborator

rustbot commented Mar 22, 2023

r? @WaffleLapkin

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

@SparrowLii SparrowLii marked this pull request as draft March 22, 2023 01:06
@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 Mar 22, 2023
@SparrowLii
Copy link
Member Author

@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 22, 2023
@bors
Copy link
Collaborator

bors commented Mar 22, 2023

⌛ Trying commit 51cfd3e with merge 529b96fb784d8a2ac0a170a5e566f13095770326...

@bors
Copy link
Collaborator

bors commented Mar 22, 2023

☀️ Try build successful - checks-actions
Build commit: 529b96fb784d8a2ac0a170a5e566f13095770326 (529b96fb784d8a2ac0a170a5e566f13095770326)

@rust-timer

This comment has been minimized.

Comment on lines +391 to +392
borrow: Cell<bool>,
mutex: RawMutex,
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't these two fields be merged into a single AtomicBool? The single-threaded version would become borrow.as_ptr().replace(true), while the multi-threaded version would use parking_lot_core::park to handle waiting.

Copy link
Member Author

@SparrowLii SparrowLii Mar 22, 2023

Choose a reason for hiding this comment

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

Thanks! It makes sense, I'm trying it soon

#[derive(Debug)]
pub struct Lock<T>(InnerLock<T>);
pub struct Lock<T> {
single_thread: bool,
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't loading PARALLEL with relaxed ordering (or maybe a non-atomic read) be just as efficient? That avoids having to copy around the bool in every lock.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (529b96fb784d8a2ac0a170a5e566f13095770326): comparison URL.

Overall result: ❌ regressions - 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@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)
2.0% [0.4%, 4.3%] 190
Regressions ❌
(secondary)
1.8% [0.6%, 6.7%] 190
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.0% [0.4%, 4.3%] 190

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.8% [0.8%, 0.8%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.7% [-1.0%, -0.5%] 7
All ❌✅ (primary) - - 0

Cycles

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)
1.8% [1.0%, 3.2%] 45
Regressions ❌
(secondary)
1.9% [0.7%, 4.7%] 29
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.8% [1.0%, 3.2%] 45

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 22, 2023
@SparrowLii
Copy link
Member Author

In my local tests, the drop of LockGuard is the main cause of performance loss. I am trying to replace lock() with with_lock() without LockGuard to see the impact on performance

@WaffleLapkin WaffleLapkin removed their assignment Apr 3, 2023
@Dylan-DPC
Copy link
Member

r? @cjgillot

assigning them as they are the assigned reviewer on the other pr as well

@Dylan-DPC Dylan-DPC 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 May 20, 2023
@Dylan-DPC
Copy link
Member

@SparrowLii any updates on this?

@SparrowLii
Copy link
Member Author

SparrowLii commented Aug 8, 2023

@Zoxc has a more completed implementation in #111713. I will first do the work of query cache next. If they still have no time to update #111713 then, I will finish this PR instead.

@Dylan-DPC
Copy link
Member

Closing this as #111713 is now merged

@Dylan-DPC Dylan-DPC closed this Oct 20, 2023
@Dylan-DPC Dylan-DPC removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. 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.

8 participants