# Limit top context identifiers and diagnostics \(\#58870\) · gitcafe/zed

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

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

Visibility: public

Requested revision: dd3521df2b490a93c171b68509880e2f773eeb53

Requested commit: dd3521df2b490a93c171b68509880e2f773eeb53

Commit: dd3521df2b490a93c171b68509880e2f773eeb53

Tree: 4491c99fe3a55a85958411f7ae210aaf5e182dca

Author: Miguel Raz Guzmán Macedo

Committer: GitHub

## Message

```
Limit top context identifiers and diagnostics (#58870)

- Replace full sort and truncate with a budgeted top-N approach for
context identifiers using truncate_to_bottom_n_sorted_by.
- Introduce MAX_DIAGNOSTICS = 10 and prune diagnostics to this limit
with select_nth_unstable_by_key, then sort the remainder.

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:

- Removed small allocations on the edit_predictions critical path by
using select_nth and sort_unstable

Co-authored-by: Nathan Barry <nathanbarry474@gmail.com>
Co-authored-by: Anthony Eid <hello@anthonyeid.me>
```

## Parents

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

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