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

Optimize LazyCell size #109483

Merged
merged 4 commits into from
Apr 1, 2023
Merged

Optimize LazyCell size #109483

merged 4 commits into from
Apr 1, 2023

Conversation

joboet
Copy link
Member

@joboet joboet commented Mar 22, 2023

LazyCell can only store either the initializing function or the data it produces, so it does not need to reserve the space for both. Similar to #107329, but uses an enum instead of a union.

@rustbot
Copy link
Collaborator

rustbot commented Mar 22, 2023

r? @Mark-Simulacrum

(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-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 22, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 22, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs


/// # Safety
/// May only be called when the state is `Uninit`.
#[cold]
Copy link
Member

Choose a reason for hiding this comment

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

I am not entirely sure if a #[cold] marker is correct here. This function is virtually guaranteed to be called (just... once).

Copy link
Member Author

Choose a reason for hiding this comment

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

Since OnceCell marks the closure as #[cold], I didn't want to change it just yet. But you are probably right that it is unnecessary here.

library/core/src/cell/lazy.rs Outdated Show resolved Hide resolved
@Mark-Simulacrum
Copy link
Member

r=me with some added comments.

@joboet
Copy link
Member Author

joboet commented Mar 28, 2023

@Mark-Simulacrum I added the comments, hopefully it is clearer now. There is also a (micro-) optimization in really_init that makes the code shorter, even if it might not help performance.

@rust-log-analyzer

This comment has been minimized.

@joboet joboet force-pushed the optimize_lazycell branch from 4f7042c to c6e4be8 Compare March 28, 2023 10:18
@joboet joboet force-pushed the optimize_lazycell branch from 091d761 to aa15467 Compare March 30, 2023 08:12
@bors
Copy link
Contributor

bors commented Mar 30, 2023

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

@joboet joboet force-pushed the optimize_lazycell branch from aa15467 to af080bf Compare March 30, 2023 12:50
@joboet
Copy link
Member Author

joboet commented Mar 30, 2023

Rebased to include the new feature name (lazy_cell) assigned in #105587.

@workingjubilee
Copy link
Member

@bors r=Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Apr 1, 2023

📌 Commit af080bf has been approved by Mark-Simulacrum

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 1, 2023
@bors
Copy link
Contributor

bors commented Apr 1, 2023

⌛ Testing commit af080bf with merge 0599b6b...

@bors
Copy link
Contributor

bors commented Apr 1, 2023

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 0599b6b to master...

1 similar comment
@bors
Copy link
Contributor

bors commented Apr 1, 2023

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 0599b6b to master...

@bors bors added merged-by-bors This PR was explicitly merged by bors. labels Apr 1, 2023
@bors bors merged commit 0599b6b into rust-lang:master Apr 1, 2023
@rustbot rustbot added this to the 1.70.0 milestone Apr 1, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0599b6b): comparison URL.

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

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)
2.1% [2.1%, 2.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.5% [-2.5%, -2.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.2% [-2.5%, 2.1%] 2

Cycles

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

@joboet joboet deleted the optimize_lazycell branch April 2, 2023 07:20
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-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.

9 participants