# Make search much faster \(\#62658\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 1e3d8b5a66af44c83632562802ccac7d15519208

Requested commit: 1e3d8b5a66af44c83632562802ccac7d15519208

Commit: 1e3d8b5a66af44c83632562802ccac7d15519208

Tree: cc6c2c758834506bde6da5624a2504e35d5ddedf

Author: Ali

Committer: GitHub

## Message

```
Make search much faster (#62658)

# Objective

Project search sends one candidate per file to its worker pool, and each
one
carried an owned `Snapshot`. Every field of `Snapshot` is cheap to clone
except
`always_included_entries`, a `Vec<Arc<RelPath>>` holding one entry per
always-included file.

With a broad file_scan_inclusions such as **/*, that vector holds an
entry per file in the project, so cloning it once per file made search
O(files²).

Partially addresses #38799 (still needs to fix the huge memory usage and
the occasional stutters) .

## Solution

Share the snapshot behind an `Arc` instead, the consumer only reads
`id()`, `abs_path()`
and `root_name()`, so nothing needs an owned copy.

## Testing
Using the [linux kernel repo](https://github.com/torvalds/linux), i
searched for `vmx_l1d_should_flush
` and `netif_rx` and its at least 60x faster on 5950x. 
with `file_scan_inclusions: ["**/*"]`


Release Notes:

- Fixed project search being very slow on projects that set a broad
`file_scan_inclusions`
```

## Parents

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

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