From: bors Date: Wed, 7 Mar 2018 22:54:54 +0000 (+0000) Subject: Auto merge of #5121 - Eh2406:string_interning, r=alexcrichton X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~2^2~55 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8fde4e3fec666b219410ae2d4945c110e9b8aa1e;p=cargo.git Auto merge of #5121 - Eh2406:string_interning, r=alexcrichton String interning This builds on the work from #5118. This interns the strings in the part of resolver that gets cloned a lot. In a test on https://github.com/rust-lang/cargo/issues/4810#issuecomment-357553286 Before we got to 1700000 ticks in ~(63 to 67) sec from #5118 After we got to 1700000 ticks in ~(42 to 45) sec The interning code itself would be much better with a `leak` function that converts a `String` to a `&'static str`. Something like: ```rust pub fn leek(s: String) -> &'static str { let ptr = s.as_ptr(); let len = s.len(); mem::forget(s); unsafe { let slice = slice::from_raw_parts(ptr, len); str::from_utf8(slice).unwrap() } } ``` but "there is no unsafe in Cargo", and I am not the best at unsafe. So I just `to_string` and lived with the extra copy. Is there a better way to hand out references? I assumed that `InternedString::new` world start appearing in profile result, and that we would want `PackageId`, and `Summary`, Et Al. to store the `InternedString`. That is why I put the interner in a shared folder. So far it is just used in the resolver. It may make sense for a lot more of the Strings to be interned, but with the extra copy... I have not explored it yet. --- 8fde4e3fec666b219410ae2d4945c110e9b8aa1e