-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Use Rc<str> and Rc<[T]> instead of Rc<String> and Rc<Vec<T>> #49645
Conversation
@bors try I'd like to check the perf. cc @Mark-Simulacrum |
Use Rc<str> and Rc<[T]> instead of Rc<String> and Rc<Vec<T>> to save a bit of memory and pointer chasing. For the `Vec<T>` case, there is one instance each of `get_mut` and `make_mut` that preclude the use of the slice type: * the `get_mut` one does `push`, so I left it as is * the `make_mut` one does a `reverse`, which would be fine but `Lrc<[T]>` does not impl `Clone` (should it?) - however, the reverse seems to be unnecessary - please if the solution makes sense Had some unrelated-looking local test failures, let's see if if CI gets them too.
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@TimNN Questionable fragment ;) Fixing the test now... |
@@ -2341,14 +2341,14 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { | |||
/// use std::collections::hash_map::{Entry, HashMap}; | |||
/// use std::rc::Rc; | |||
/// | |||
/// let mut map: HashMap<Rc<String>, u32> = HashMap::new(); | |||
/// map.insert(Rc::new("Stringthing".to_string()), 15); | |||
/// let mut map: HashMap<Rc<str>, u32> = HashMap::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.
Why these doc changes?
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 think we shouldn't promote use of Rc<String>
, rather show that Rc<str>
is now feasible and preferable.
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The try build is successful. Again, the reply is missing, probably because new commits are pushed in between. Anyway, please schedule |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Try build queued for perf. |
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.
so r=me for the compiler stuff, but I don't feel qualified to r+ the changes to the libstd docs
r? @steveklabnik for the changes to hashmap example etc |
Ignoring the spurious |
☔ The latest upstream changes (presumably #49696) made this pull request unmergeable. Please resolve the merge conflicts. |
There is one instace where Lrc::get_mut().unwrap() is used on the reference to make a push, this cannot be converted. One instance of Lrc::make_mut() was removed -- the side effect of changing the original vector cannot have mattered since make_mut() might have cloned it.
Updated. |
☔ The latest upstream changes (presumably #49672) made this pull request unmergeable. Please resolve the merge conflicts. |
Hmm. I'm torn on this change. I wouldn't expect a real performance win -- as we saw on perf, this is basically in the noise, which is what I would expect. (Note also that even when judged from a "micro-efficiency" perspective, this is not an obvious win: My bigger concern though is that constructing a Note all that we don't really get much increased flexibility here. e.g.,, given a So in summary:
cc @rust-lang/compiler -- thoughts? |
👍 for elegance |
Yeah - you need |
Actually I would have expected a performance loss because constructing a |
I've been wanting to get rid of the |
Ping from triage! What's the status of this PR? |
1 similar comment
Ping from triage! What's the status of this PR? |
Looks like the change is not unanimous, and a significant part is likely to be refactored away, so I'll close it. |
to save a bit of memory and pointer chasing.
For the
Vec<T>
case, there is one instance each ofget_mut
andmake_mut
that preclude the use of the slice type:get_mut
one doespush
, so I left it as ismake_mut
one does areverse
, which would be fine butLrc<[T]>
does not implClone
(should it?) - however, the reverse seems to be unnecessary - please check if the solution makes senseHad some unrelated-looking local test failures, let's see if if CI gets them too.