-
Notifications
You must be signed in to change notification settings - Fork 2.6k
refactor: replace InternedString with Cow in IndexPackage #15559
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
Conversation
5fdaca9
to
de4a534
Compare
I would recommend at least doing some benchmarking using our bench suite. https://github.com/rust-lang/cargo/tree/master/benches contains some documentation, and particularly the |
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could change InternString::from_cow
to something like:
impl<'a> From<Cow<'a, str>> for InternedString {
fn from(cs: Cow<'a, str>) -> Self {
let mut cache = interned_storage();
let s = cache.get(cs.as_ref()).copied().unwrap_or_else(|| {
let s = cs.into_owned().leak();
cache.insert(s);
s
});
InternedString { inner: s }
}
}
So in other places we can rely on Into<InternedString>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weihanglo Do you think it makes sense to replace all instances of InternedString::new
with .into()
where possible? There are quite a few usages of InternedString::new
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with wherever reasonable. Could also leave them for future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with wherever reasonable. Could also leave them for future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update all of them in a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have done it in this commit. 5f90098
(#15559).
I am unsure if it worsens the readability. Maybe we shouldn't do it at all 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with either. Looks like this is ready for review/merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It is ready for review. Thank you!
I’ve tested this change several times using the resolve_ws/rust benchmark suite. My test env: Model Name: MacBook Pro
Chip: Apple M4 Max
Total Number of Cores: 14 (10 performance and 4 efficiency)
Memory: 36 GB Test result: First round:
Second round:
Third round:
Fourth round:
|
I’ve tested this change several times using the resolve_ws/tikv benchmark suite. My test env: Model Name: MacBook Pro
Chip: Apple M4 Max
Total Number of Cores: 14 (10 performance and 4 efficiency)
Memory: 36 GB Test result: First round:
Second round:
Third round:
Fourth round:
|
Signed-off-by: 0xPoe <techregister@pm.me>
Signed-off-by: 0xPoe <techregister@pm.me>
…odebase Signed-off-by: 0xPoe <techregister@pm.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔢 Self-check (PR reviewed by myself and ready for feedback)
-
Code compiles successfully
-
Benchmark Tests
-
All tests pass
-
PR title and description updated
-
Documentation PR created (or confirmed not needed)
-
PR size is reasonable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference shown in the benchmark seems insignificant, so going to merge this. Thank you so much!
Thanks for your review! 💚 💙 💜 💛 ❤️ |
Update cargo 6 commits in fc1518ef02b77327d70d4026b95ea719dd9b8c51..2251525ae503fa196f6d7f9ce6d32eccb2d5f044 2025-06-06 04:49:44 +0000 to 2025-06-16 22:01:27 +0000 - feat: Add custom completer for `cargo remove <TAB>` (rust-lang/cargo#15662) - chore(deps): update msrv (3 versions) to v1.85 (rust-lang/cargo#15668) - refactor: replace InternedString with Cow in IndexPackage (rust-lang/cargo#15559) - highlight the correct words (rust-lang/cargo#15659) - CHANGELOG.md: typo (rust-lang/cargo#15660) - Use `Not::not` rather than a custom `is_false` function (rust-lang/cargo#15645)
Rollup merge of #142632 - ehuss:update-cargo, r=ehuss Update cargo 6 commits in fc1518ef02b77327d70d4026b95ea719dd9b8c51..2251525ae503fa196f6d7f9ce6d32eccb2d5f044 2025-06-06 04:49:44 +0000 to 2025-06-16 22:01:27 +0000 - feat: Add custom completer for `cargo remove <TAB>` (rust-lang/cargo#15662) - chore(deps): update msrv (3 versions) to v1.85 (rust-lang/cargo#15668) - refactor: replace InternedString with Cow in IndexPackage (rust-lang/cargo#15559) - highlight the correct words (rust-lang/cargo#15659) - CHANGELOG.md: typo (rust-lang/cargo#15660) - Use `Not::not` rather than a custom `is_false` function (rust-lang/cargo#15645)
What does this PR try to resolve?
ref #14834
As described in the issue, we want to move IndexPackage into cargo-util-schemas. However, it contains InternedString fields, which we don't want to expose as part of the public API.
This PR replaces InternedString with Cow.
And also, as @weihanglo's suggested, I implemented the From/Into trait to simplify code.
From Cow tarit implementation:
42f593f
(#15559)Replace InternedString with
into()
across the whole codebase:5f90098
(#15559)I am unsure if it worsens the readability. Feel free to comment.
How should we test and review this PR?
It shouldn't change or break any tests.
Benchmark 1: #15559 (comment)
Benchmark 2: #15559 (comment)
Additional information
None