# multi_buffer: Use stable storage for buffer IDs \(\#46884\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 9b9f25ff39c733478e666dbc496b0cd34787050e

Requested commit: 9b9f25ff39c733478e666dbc496b0cd34787050e

Commit: 9b9f25ff39c733478e666dbc496b0cd34787050e

Tree: e115f4af2275a0a07c56dc61d15761a6e33e4380

Author: Piotr Osiewicz

Committer: GitHub

## Message

```
multi_buffer: Use stable storage for buffer IDs (#46884)

Long story short:
1. Whenever we pick a buffer for mutation in

https://github.com/zed-industries/zed/blob/b8c5f672cdf8ed3c1f4c8016f2b8d6d84b7a7a9c/crates/multi_buffer/src/multi_buffer.rs#L3831,
we seed from a hashmap<BufferId, _>.
2. That HashMap is not RNG-seeded by
itself (good), but the BufferIds are: they are derived from entity ID in

https://github.com/zed-industries/zed/blob/b8c5f672cdf8ed3c1f4c8016f2b8d6d84b7a7a9c/crates/project/src/buffer_store.rs#L641

3.^ was introduced in https://github.com/zed-industries/zed/pull/10347
4.The HashMap is not randomized, but the order of it's values could
shift
when the keys (buffer ids) change.
5. Thus, we'll end up mutating a
different buffer in the multi-buffer when BufferIds shift around.

Our "fix" is that we're using a btreemap for buffer storage, which
should ensure that the order of iteration (and seeding) the candidates
matches up with the order of buffer creation.

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>

Closes #ISSUE

Release Notes:

- N/A

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
```

## Parents

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

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