project: Increase search detect yield threshold to 20KB (#47824)

Xiaobo Liu created

Release Notes:

- Improved CPU switching frequency for project search

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>

Change summary

crates/project/src/search.rs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

Detailed changes

crates/project/src/search.rs 🔗

@@ -345,16 +345,16 @@ impl SearchQuery {
 
         let mut text = String::new();
         let mut bytes_read = 0;
-        // Yield from this function every 128 bytes scanned.
-        const YIELD_THRESHOLD: usize = 128;
+        // Yield from this function every 20KB scanned.
+        const YIELD_THRESHOLD: usize = 20 * 1024;
         match self {
             Self::Text { search, .. } => {
                 if query_str.contains('\n') {
                     reader.read_to_string(&mut text)?;
                     Ok(search.is_match(&text))
                 } else {
-                    // Yield from this function every 128 bytes scanned.
-                    const YIELD_THRESHOLD: usize = 128;
+                    // Yield from this function every 20KB scanned.
+                    const YIELD_THRESHOLD: usize = 20 * 1024;
                     while reader.read_line(&mut text)? > 0 {
                         if search.is_match(&text) {
                             return Ok(true);