mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
gpui_shared_string: Avoid intermediate string allocation when deserializing a SharedString (#65089)
## Summary This PR improves how we deserialize SharedStrings. Since we moved to `SmolStr` under the hood some time ago, which takes a string by `impl AsRef<str>` in its constructor, we can get rid here of allocating a string where possible in favor of using a stringvisitor during deserialization. This provides us with some decent improvements. ## Testing The benchmark results are the following: | Case | `from_str` before | `from_str` after | Δ | |---|---:|---:|---:| | short (≤23 B, inline) | 23.1 µs | 11.6 µs | −50% | short, escaped | 33.2 µs | 22.4 µs | −32% | | long (~66 B, heap) | 46.9 µs | 31.4 µs | −33% | | long, escaped | 307.6 µs | 267.6 µs | −13% | ## Self-review - [X] I've reviewed my diff for quality, security, reliability, and performance. - [-] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [-] Tests cover the new or changed behavior. Release Notes: - N/A - [GPUI] Improved memory usage and performance when deserializing SharedStrings.
This commit is contained in:
Generated
-1
@@ -17164,7 +17164,6 @@ version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4aaa7368fcf4852a4c2dd92df0cace6a71f2091ca0a23391ce7f3a31833f1523"
|
||||
dependencies = [
|
||||
"borsh",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ doctest = false
|
||||
[dependencies]
|
||||
schemars.workspace = true
|
||||
serde.workspace = true
|
||||
smol_str = "0.3.6"
|
||||
smol_str = { version = "0.3.6", default-features = false, features = ["serde"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -205,7 +205,6 @@ impl<'de> Deserialize<'de> for SharedString {
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let s = String::deserialize(deserializer)?;
|
||||
Ok(SharedString::new(&s))
|
||||
SmolStr::deserialize(deserializer).map(SharedString)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user