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

Remove metadata decoding DefPathHash cache #119265

Merged
merged 2 commits into from
Dec 24, 2023

Conversation

Mark-Simulacrum
Copy link
Member

My expectation is that this cache is largely useless. Decoding a DefPathHash from metadata is essentially a pair of memory loads - there's no heavyweight processing involved. Caching it behind a HashMap just adds extra cost and incurs hashing overheads for the indices.

Based on #119238.

Instead, we store just the local crate hash as a bare u64. On decoding,
we recombine it with the crate's stable crate ID stored separately in
metadata. The end result is that we save ~8 bytes/DefIndex in metadata
size.

One key detail here is that we no longer distinguish in encoded metadata
between present and non-present DefPathHashes. It used to be highly
likely we could distinguish as we used DefPathHash::default(), an
all-zero representation. However in theory even that is fallible as
nothing strictly prevents the StableCrateId from being zero.
This cache is largely useless. Decoding a DefPathHash from metadata is
essentially a pair of memory loads - there's no heavyweight processing
involved. Caching it behind a HashMap just adds extra cost and incurs
hashing overheads.
@Mark-Simulacrum
Copy link
Member Author

@bors try @rust-timer queue

@rustbot
Copy link
Collaborator

rustbot commented Dec 23, 2023

r? @TaKO8Ki

(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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 23, 2023
@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 Dec 23, 2023
@bors
Copy link
Contributor

bors commented Dec 23, 2023

⌛ Trying commit f098f34 with merge bd2706d...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 23, 2023
Remove metadata decoding DefPathHash cache

My expectation is that this cache is largely useless. Decoding a DefPathHash from metadata is essentially a pair of memory loads - there's no heavyweight processing involved. Caching it behind a HashMap just adds extra cost and incurs hashing overheads for the indices.

Based on rust-lang#119238.
@bors
Copy link
Contributor

bors commented Dec 23, 2023

☀️ Try build successful - checks-actions
Build commit: bd2706d (bd2706db8872d068a8943e19851e1a1428ea1f5b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (bd2706d): comparison URL.

Overall result: ❌✅ regressions and improvements - 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)
0.8% [0.8%, 0.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.5% [-1.4%, -0.2%] 96
Improvements ✅
(secondary)
-1.1% [-3.0%, -0.2%] 52
All ❌✅ (primary) -0.5% [-1.4%, 0.8%] 97

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)
3.5% [2.0%, 6.0%] 4
Improvements ✅
(primary)
-1.8% [-3.4%, -0.8%] 34
Improvements ✅
(secondary)
-2.2% [-2.9%, -1.4%] 13
All ❌✅ (primary) -1.8% [-3.4%, -0.8%] 34

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.3% [-1.7%, -0.9%] 13
Improvements ✅
(secondary)
-2.3% [-2.9%, -1.0%] 15
All ❌✅ (primary) -1.3% [-1.7%, -0.9%] 13

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)
-1.0% [-2.8%, -0.1%] 114
Improvements ✅
(secondary)
-1.7% [-4.8%, -0.0%] 72
All ❌✅ (primary) -1.0% [-2.8%, -0.1%] 114

Bootstrap: 669.829s -> 670.678s (0.13%)
Artifact size: 312.74 MiB -> 312.59 MiB (-0.05%)

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

Regression looks like possible noise to me, either way outweighed by improvements. My takeaway is that this is a good change to make, seems like a slight win and also simplifies code.

@cjgillot
Copy link
Contributor

r=me once the other PR lands.

@Mark-Simulacrum Mark-Simulacrum added the perf-regression-triaged The performance regression has been triaged. label Dec 24, 2023
@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Dec 24, 2023

📌 Commit f098f34 has been approved by cjgillot

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

bors commented Dec 24, 2023

⌛ Testing commit f098f34 with merge ebb821f...

@bors
Copy link
Contributor

bors commented Dec 24, 2023

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing ebb821f to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 24, 2023
@bors bors merged commit ebb821f into rust-lang:master Dec 24, 2023
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Dec 24, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ebb821f): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.9% [0.9%, 0.9%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.6% [-2.1%, -0.2%] 101
Improvements ✅
(secondary)
-1.2% [-3.2%, -0.2%] 65
All ❌✅ (primary) -0.6% [-2.1%, 0.9%] 102

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)
3.3% [2.1%, 6.0%] 5
Improvements ✅
(primary)
-1.3% [-1.3%, -1.3%] 1
Improvements ✅
(secondary)
-1.8% [-3.0%, -1.2%] 4
All ❌✅ (primary) -1.3% [-1.3%, -1.3%] 1

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.3% [-1.6%, -0.9%] 9
Improvements ✅
(secondary)
-2.3% [-3.1%, -1.0%] 10
All ❌✅ (primary) -1.3% [-1.6%, -0.9%] 9

Binary size

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

Bootstrap: 669.722s -> 671.86s (0.32%)
Artifact size: 312.65 MiB -> 312.67 MiB (0.01%)

@Mark-Simulacrum Mark-Simulacrum deleted the remove-cache branch December 24, 2023 17:23
EliseZeroTwo pushed a commit to EliseZeroTwo/rust that referenced this pull request Dec 24, 2023
…llot

Remove metadata decoding DefPathHash cache

My expectation is that this cache is largely useless. Decoding a DefPathHash from metadata is essentially a pair of memory loads - there's no heavyweight processing involved. Caching it behind a HashMap just adds extra cost and incurs hashing overheads for the indices.

Based on rust-lang#119238.
@Kobzol
Copy link
Contributor

Kobzol commented Dec 26, 2023

The single small regression is probably just noise for that benchmark returning back to steady state. In any case, it would be definitely offset by the wide range of improvements across the board.

@rustbot label: +perf-regression-triaged

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-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.

7 participants