Two small changes that avoid touching the bytes of text that hasn't
changed:
- `SharedString` equality checks whether both sides point at the same
bytes before comparing them. `SmolStr` compares heap-allocated and
static strings byte by byte even when both are clones of the same
allocation, which is common when a view clones the same label into its
elements every frame. Strings of up to 23 bytes are stored inline and
still use `SmolStr`'s comparison. `Hash` is now implemented by hand
(clippy rejects deriving it alongside a manual `PartialEq`) and hashes
exactly as before.
- A `&'static str` text child (e.g. `div().child("Some label")`) is
wrapped with `SharedString::new_static` instead of copied every frame,
which allocated for strings longer than 23 bytes. Its comparisons now
hit the pointer check above.
Release Notes:
- N/A
- [GPUI] Avoid allocating for a SharedString in `imp Element for
&'static str`
## 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.
Also updates CI to always run this - that way we ensure that disabling
or enabling tests does not become stale at some point and thus can
safely add this.
Release Notes:
- N/A
- [GPUI] N/A
Relicenses `zlog`, `ztracing`, and `ztracing_macro` from
GPL-3.0-or-later to Apache-2.0.
GPUI depends on `ztracing`, which depends on `zlog`, so these crates
have to be non-copyleft for GPUI to ship as a permissively licensed
project.
- Switched the `license` field to `Apache-2.0` in all three manifests.
- Added the `LICENSE-APACHE` symlink to `zlog`, and dropped the
`LICENSE-GPL` symlinks from all three. `ztracing` and `ztracing_macro`
already carried both symlinks; now the on-disk license matches the
manifest.
- Declared `license = "Apache-2.0"` for `gpui_util`, which had a
`LICENSE-APACHE` symlink but no `license` field. `script/check-licenses`
doesn't catch that, since it only inspects symlinks.
No source changes; none of these crates carry GPL headers or in-source
license references.
Checked the rest of the subtree while here: the only first-party crates
reachable from `ztracing` via `cargo tree -e normal` are `collections`,
`gpui_util`, `zlog`, and `ztracing_macro`, all Apache-2.0 now.
Third-party deps (`tracing`, `tracing-subscriber`, `chrono`, `log`,
`anyhow`, `tracy-client`) are MIT/Apache.
`script/check-licenses` passes.
Release Notes:
- N/A
This reduces the size of Sharedstring from 32 bytes to 24 while also
allowing for small-string optimization, meaning strings with length < 23
bytes will not actually allocate.
Release Notes:
- N/A or Added/Fixed/Improved ...
- `language_model` no longer depends on provider-specific crates such as
`anthropic` and `open_ai` (inverted dependency)
- `language_model_core` was extracted from `language_model` which
contains the types for the provider-specific crates to convert to/from.
- `gpui::SharedString` has been extracted into its own crate (still
exposed by `gpui`), so `language_model_core` and provider API crates
don't have to depend on `gpui`.
- Removes some unnecessary `&'static str` | `SharedString` -> `String`
-> `SharedString` conversions across the codebase.
- Extracts the core logic of the cloud `LanguageModelProvider` into its
own crate with simpler dependencies.
Release Notes:
- N/A
---------
Co-authored-by: John Tur <john-tur@outlook.com>