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

Add cache for allocate_str #127638

Merged
merged 1 commit into from
Jul 16, 2024
Merged

Add cache for allocate_str #127638

merged 1 commit into from
Jul 16, 2024

Conversation

adwinwhite
Copy link
Contributor

Best effort cache for string allocation in const eval.

Fixes rust-lang/miri#3470.

@rustbot
Copy link
Collaborator

rustbot commented Jul 12, 2024

r? @pnkfelix

rustbot has assigned @pnkfelix.
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
Copy link
Collaborator

rustbot commented Jul 12, 2024

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

@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 Jul 12, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Jul 12, 2024

We recreate the InterpCtxt on every constant, so this does not do any cross-constant caching, which is where it is actually needed I believe. This would need to work similar to how we create only a single alloc id for static items.

@oli-obk oli-obk assigned oli-obk and unassigned pnkfelix Jul 12, 2024
@adwinwhite
Copy link
Contributor Author

Oh, I didn't realize InterpCtxt isn't shared.

Does it mean I should put the cache in GlobalCtxt and use TyCtxt::allocate_bytes to allocate global memory for these strings?
AllocId/Pointer is unique globally and InterpCtxt can read global memory so it should work.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 12, 2024

I think changing allocate_bytes to use https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.reserve_and_set_dedup internally will do exactly what we want, as we already have a cache

@adwinwhite
Copy link
Contributor Author

This approach looks elegant!

The only problem is that reserve_and_set_dedup doesn't work with GlobalAlloc::Memory(..).
Should we inline an unrestricted version of reserve_and_set_dedup into allocate_bytes by hand or just allow GlobalAlloc::Memory in reserve_and_set_dedup?

@oli-obk
Copy link
Contributor

oli-obk commented Jul 12, 2024

just allow GlobalAlloc::Memory in reserve_and_set_dedup?

yea, we originally restricted it because we didn't have a use case, so it seems fine to just remove the check and permit it

@rustbot
Copy link
Collaborator

rustbot commented Jul 13, 2024

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

@adwinwhite
Copy link
Contributor Author

adwinwhite commented Jul 14, 2024 via email

@oli-obk
Copy link
Contributor

oli-obk commented Jul 15, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Jul 15, 2024

📌 Commit e595f3d has been approved by oli-obk

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 Jul 15, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Jul 15, 2024

@bors r- actually let's perf it first

@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 Jul 15, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Jul 15, 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 Jul 15, 2024
@bors
Copy link
Contributor

bors commented Jul 15, 2024

⌛ Trying commit e595f3d with merge b43ab65...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 15, 2024
Add cache for `allocate_str`

Best effort cache for string allocation in const eval.

Fixes [rust-lang/miri#3470](rust-lang/miri#3470).
@bors
Copy link
Contributor

bors commented Jul 15, 2024

☀️ Try build successful - checks-actions
Build commit: b43ab65 (b43ab65695ef748dbb70d60cb1ee60b15a3decba)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b43ab65): comparison URL.

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

Max RSS (memory usage)

Results (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)
- - 0
Regressions ❌
(secondary)
3.7% [3.7%, 3.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

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

Binary size

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

Bootstrap: 700.232s -> 700.469s (0.03%)
Artifact size: 328.70 MiB -> 328.66 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 15, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Jul 15, 2024

bors r plus

@bors rollup-

@bors
Copy link
Contributor

bors commented Jul 15, 2024

📌 Commit e595f3d has been approved by oli-obk

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 15, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 15, 2024
Add cache for `allocate_str`

Best effort cache for string allocation in const eval.

Fixes [rust-lang/miri#3470](rust-lang/miri#3470).
@bors
Copy link
Contributor

bors commented Jul 16, 2024

⌛ Testing commit e595f3d with merge 5c84886...

@bors
Copy link
Contributor

bors commented Jul 16, 2024

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 5c84886 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 16, 2024
@bors bors merged commit 5c84886 into rust-lang:master Jul 16, 2024
7 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jul 16, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5c84886): 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)
0.1% [0.1%, 0.1%] 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

Results (secondary -3.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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-3.4%, -3.4%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 700.582s -> 700.173s (-0.06%)
Artifact size: 328.68 MiB -> 328.67 MiB (-0.00%)

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

Add global string de-duplication cache
7 participants