Skip to content

Conversation

@lukas-code
Copy link
Member

Currently, when the last Rc<T> or Arc<T> is dropped and the destructor of T panics, the allocation will be leaked. This leak is unnecessary since the data cannot be (safely) accessed again and Box already deallocates in this case, so let's do the same for Rc and Arc, too.

@rustbot
Copy link
Collaborator

rustbot commented Oct 27, 2024

r? @tgross35

rustbot has assigned @tgross35.
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 Oct 27, 2024

// Destroy the contained object.
// We cannot use `get_mut_unchecked` here, because `self.alloc` is borrowed.
ptr::drop_in_place(&mut (*self.ptr.as_ptr()).value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this just use raw mut?

ptr::drop_in_place(&raw mut self.ptr.as_ptr().value);

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I understand, drop_in_place always works as if it's argument was &mut T and only uses *mut T in the signature for compatibility reasons (see #103957 and #111807).

So, yes, this could use &raw mut, but the pointer would just automatically be reborrowed as a reference anyway, so i used &mut directly for clarity.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, thanks for the follow up

@tgross35
Copy link
Contributor

I don't really expect anything here but just in case the drop path changes are sensitive somehow:

@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 Oct 27, 2024
@bors
Copy link
Collaborator

bors commented Oct 27, 2024

⌛ Trying commit 4a71a59 with merge 48c9fdd...

@bors
Copy link
Collaborator

bors commented Oct 27, 2024

☀️ Try build successful - checks-actions
Build commit: 48c9fdd (48c9fdd2bf3f86220bdf68cf602e42d7f9e0c4b5)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (48c9fdd): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.3% [0.3%, 0.3%] 1
Regressions ❌
(secondary)
1.5% [0.8%, 2.6%] 7
Improvements ✅
(primary)
-0.9% [-1.3%, -0.2%] 3
Improvements ✅
(secondary)
-1.5% [-1.5%, -1.5%] 1
All ❌✅ (primary) -0.6% [-1.3%, 0.3%] 4

Max RSS (memory usage)

Results (primary 2.5%, secondary 3.0%)

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)
5.0% [2.9%, 7.9%] 3
Regressions ❌
(secondary)
3.0% [1.4%, 4.5%] 2
Improvements ✅
(primary)
-5.3% [-5.3%, -5.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.5% [-5.3%, 7.9%] 4

Cycles

Results (primary -1.0%, secondary 0.4%)

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)
2.8% [2.4%, 3.2%] 3
Improvements ✅
(primary)
-1.0% [-1.0%, -1.0%] 1
Improvements ✅
(secondary)
-6.9% [-6.9%, -6.9%] 1
All ❌✅ (primary) -1.0% [-1.0%, -1.0%] 1

Binary size

Results (primary 0.0%, secondary 0.5%)

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.1% [0.0%, 0.3%] 25
Regressions ❌
(secondary)
0.5% [0.0%, 4.0%] 43
Improvements ✅
(primary)
-0.1% [-0.3%, -0.0%] 21
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [-0.3%, 0.3%] 46

Bootstrap: 782.673s -> 783.739s (0.14%)
Artifact size: 333.75 MiB -> 333.75 MiB (0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 28, 2024
@tgross35
Copy link
Contributor

The main regression is regression-31157 which is a pretty tiny crate doing parsing things, added to test a huge regression. I think that is acceptable given this is a nice usability improvement (especially Arc considering the useccase is probably to leak memory and continue) but just to see, could you test adding #[inline] to Rc's drop? Arc's drop has it already, thinking maybe it would reduce a call now that deallocate happens elsewhere.

@lukas-code
Copy link
Member Author

Applied the same inline/outline trick from Arc to Rc. Let's see if this helps at 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 Oct 28, 2024
@bors
Copy link
Collaborator

bors commented Oct 28, 2024

⌛ Trying commit 02ee639 with merge 01c529d...

@bors
Copy link
Collaborator

bors commented Oct 28, 2024

☀️ Try build successful - checks-actions
Build commit: 01c529d (01c529df780282284b312a27a6aaaddae3b6602f)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (01c529d): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.9% [0.9%, 0.9%] 1
Regressions ❌
(secondary)
2.2% [1.1%, 3.5%] 6
Improvements ✅
(primary)
-0.8% [-1.6%, -0.2%] 4
Improvements ✅
(secondary)
-0.5% [-0.6%, -0.3%] 7
All ❌✅ (primary) -0.4% [-1.6%, 0.9%] 5

Max RSS (memory usage)

Results (primary -0.7%, secondary 2.9%)

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)
4.2% [4.2%, 4.2%] 1
Regressions ❌
(secondary)
2.9% [2.4%, 3.4%] 2
Improvements ✅
(primary)
-5.5% [-5.5%, -5.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-5.5%, 4.2%] 2

Cycles

Results (primary 0.0%, 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)
1.2% [1.2%, 1.2%] 1
Regressions ❌
(secondary)
3.7% [3.2%, 4.2%] 3
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [-1.1%, 1.2%] 2

Binary size

Results (primary 0.0%, secondary 1.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.1% [0.0%, 0.2%] 23
Regressions ❌
(secondary)
1.1% [0.0%, 8.7%] 43
Improvements ✅
(primary)
-0.1% [-0.1%, -0.0%] 20
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [-0.1%, 0.2%] 43

Bootstrap: 782.325s -> 785.165s (0.36%)
Artifact size: 333.64 MiB -> 333.76 MiB (0.04%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 29, 2024
@tgross35
Copy link
Contributor

There probably isn't too much to be done regarding perf, all of the regressions come from one small crate. The code changes look good to me.

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 29, 2024

📌 Commit 02ee639 has been approved by tgross35

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 Oct 29, 2024
@bors
Copy link
Collaborator

bors commented Oct 29, 2024

⌛ Testing commit 02ee639 with merge e473783...

@bors
Copy link
Collaborator

bors commented Oct 29, 2024

☀️ Test successful - checks-actions
Approved by: tgross35
Pushing e473783 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 29, 2024
@bors bors merged commit e473783 into rust-lang:master Oct 29, 2024
7 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 29, 2024
@lukas-code lukas-code deleted the rc-plug-leaks branch October 29, 2024 19:47
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e473783): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

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

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.6% [0.6%, 0.6%] 1
Regressions ❌
(secondary)
2.3% [1.1%, 3.5%] 6
Improvements ✅
(primary)
-0.9% [-1.4%, -0.3%] 3
Improvements ✅
(secondary)
-0.4% [-0.6%, -0.2%] 5
All ❌✅ (primary) -0.5% [-1.4%, 0.6%] 4

Max RSS (memory usage)

Results (primary -1.4%, secondary 2.6%)

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.7% [3.0%, 4.4%] 2
Regressions ❌
(secondary)
2.6% [2.6%, 2.6%] 1
Improvements ✅
(primary)
-3.9% [-5.9%, -1.7%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.4% [-5.9%, 4.4%] 6

Cycles

Results (primary 1.3%, secondary 0.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.1% [1.9%, 2.3%] 3
Regressions ❌
(secondary)
3.1% [2.2%, 3.9%] 5
Improvements ✅
(primary)
-1.2% [-1.2%, -1.2%] 1
Improvements ✅
(secondary)
-2.7% [-3.1%, -2.3%] 5
All ❌✅ (primary) 1.3% [-1.2%, 2.3%] 4

Binary size

Results (primary 0.0%, secondary 1.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.1% [0.0%, 0.3%] 27
Regressions ❌
(secondary)
1.1% [0.0%, 8.8%] 43
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 20
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [-0.2%, 0.3%] 47

Bootstrap: 784.701s -> 784.999s (0.04%)
Artifact size: 333.58 MiB -> 333.64 MiB (0.02%)

@rylev
Copy link
Member

rylev commented Nov 5, 2024

Marking as triaged based on the analysis here

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Nov 5, 2024
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. 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-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.

6 participants