zed/crates/gpui_wgpu
tidely d0f797a38c
wgpu: Only store embedded fonts once in memory (#62192)
# Objective

Zed's `wgpu` backend currently allocates memory for fonts, even if they
are statically available in memory. Zed embeds 8 fonts, which accounts
for about 1.6 megabytes of memory. This change should reduce memory
usage by that amount on the `wgpu` backend. (Linux and Web)

For more context, this is the function signature for `load_font_data`:

```rust
/// Loads a font data into the `Database`.
///
/// Will load all font faces in case of a font collection.
pub fn load_font_data(&mut self, data: Vec<u8>) {
    self.load_font_source(Source::Binary(alloc::sync::Arc::new(data)));
}
```

## Solution

Instead of calling `fontdb::Database::load_font_data`, which needs an
owned `Vec`, use `load_font_source`, which allows us to create an `Arc`
ourselves, which doesn't require ownership of the underlying data.

## Testing

All tests pass

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Slightly improved memory usage on Linux
2026-08-06 15:02:42 +00:00
..
benches
src
Cargo.toml
LICENSE-APACHE