# multibuffer: Speed up anchor resolution by avoiding an excerpts seek \(\#53340\) · gitcafe/zed

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

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

Visibility: public

Requested revision: aa8150527ed52bd258218e15d8ac3d400587312d

Requested commit: aa8150527ed52bd258218e15d8ac3d400587312d

Commit: aa8150527ed52bd258218e15d8ac3d400587312d

Tree: d028b622b70a0b7ad621e528395f3cd27b91107b

Author: Cole Miller

Committer: GitHub

## Message

```
multibuffer: Speed up anchor resolution by avoiding an excerpts seek (#53340)

Before, every creation of `AnchorSeekTarget` called
`MultiBufferSnapshot::buffer_for_path`, which seeks the excerpts sum
tree. Now we avoid that by

- looking up the buffer snapshot for the anchor's buffer in the
`buffers` map (keyed by `BufferId`)
- handling the case where the anchor's buffer doesn't exist at the
original path key with a separate `AnchorSeekTarget::Missing` variant

We also added a separate optimization to `AnchorSeekTarget::cmp`, to
skip the full `PathKey` comparison when the cursor's `PathKeyIndex` is
the same as the anchor's. This should help with singleton multibuffers.

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 is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A

---------

Co-authored-by: Anthony Eid <hello@anthonyeid.me>
```

## Parents

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

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