# wgpu: Only store embedded fonts once in memory \(\#62192\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/d0f797a38c751cff745108e458bbc5ec73c70738)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: d0f797a38c751cff745108e458bbc5ec73c70738

Requested commit: d0f797a38c751cff745108e458bbc5ec73c70738

Commit: d0f797a38c751cff745108e458bbc5ec73c70738

Tree: 49673d622336d48146d3785b6b034987ae04e49c

Author: tidely

Committer: GitHub

## Message

````
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
````

## Parents

- [b5796233bd92695da23b7965cd991552a9dbc0c6](https://git.cafe/gitcafe/zed/commit/b5796233bd92695da23b7965cd991552a9dbc0c6?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/d0f797a38c751cff745108e458bbc5ec73c70738?format=markdown)
