Skip to content

editor: Reduce allocations during editor prepaint - #61290

Merged
ChristopherBiscardi merged 6 commits into
zed-industries:mainfrom
tidely:misc-editor-prepaint
Jul 20, 2026
Merged

editor: Reduce allocations during editor prepaint#61290
ChristopherBiscardi merged 6 commits into
zed-industries:mainfrom
tidely:misc-editor-prepaint

Conversation

@tidely

@tidely tidely commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Found some unnecessary allocations and an .unwrap() while working on a separate issue. The PR makes no behavior changes and should be trivial to review.

Testing

All tests pass. These changes are not expected to change any behavior.

None of the changes are interleaving, so it should be easy to review top-down. Reasoning for each change can be read from individual commit messages.

Release Notes:

  • N/A or Added/Fixed/Improved ...

tidely added 6 commits July 19, 2026 15:35
Our `.all()` only requires the current element for evaluation, meaning
we don't need to store all elements at once, and can get rid of the
whole Vec
These instances are turned into iterators right away, so we don't need
to allocate them on the heap first. The elements are all small, meaning
stack space isnt an issue.
`is_none() { return None }` is a bad pattern, use ? instead. Saves the
`is_some_and` later.
Calling the right constructor prevents for example turning a `Arc<str>`
into a `&str` and then allocating a new buffer for it, when we could
just reuse the owned `Arc` for free
`x_and_width` unnecessarily returned a Option, because we stored it
directly into a variable in a larger scope, store it first locally which
lets us get rid of a unwrap
Using iterators here allows us to know the size of the `Vec` that will
be allocated beforehand, allowing O(1) allocation instead of ammortized
O(1).
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 19, 2026
@zed-community-bot zed-community-bot Bot added community champion Issues filed by our amazing community champions! 🫶 guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions labels Jul 19, 2026

@ChristopherBiscardi ChristopherBiscardi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@ChristopherBiscardi
ChristopherBiscardi added this pull request to the merge queue Jul 20, 2026
Merged via the queue into zed-industries:main with commit 04c247d Jul 20, 2026
58 checks passed
@ChristopherBiscardi ChristopherBiscardi self-assigned this Jul 20, 2026
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
Found some unnecessary allocations and an `.unwrap()` while working on a
separate issue. The PR makes no behavior changes and should be trivial
to review.

## Testing

All tests pass. These changes are not expected to change any behavior.

None of the changes are interleaving, so it should be easy to review
top-down. Reasoning for each change can be read from individual commit
messages.

Release Notes:

- N/A or Added/Fixed/Improved ...
playdohface pushed a commit to playdohface/zed that referenced this pull request Aug 29, 2026
Found some unnecessary allocations and an `.unwrap()` while working on a
separate issue. The PR makes no behavior changes and should be trivial
to review.

## Testing

All tests pass. These changes are not expected to change any behavior.

None of the changes are interleaving, so it should be easy to review
top-down. Reasoning for each change can be read from individual commit
messages.

Release Notes:

- N/A or Added/Fixed/Improved ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement community champion Issues filed by our amazing community champions! 🫶 guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants