Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion crates/fff-core/benches/fuzzy_search_bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use criterion::{BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main};
use fff_search::{FilePicker, FilePickerOptions, FuzzySearchOptions, PaginationArgs, QueryParser};
use std::{hint::black_box, time::Duration};

Expand Down Expand Up @@ -87,6 +87,31 @@ fn bench_picker(
});
}
}
// Measure the same final keystroke, with and without a reusable prefix.
let parsed = parser.parse("group_57/controller_570");
let options = FuzzySearchOptions {
max_threads: 4,
pagination: PaginationArgs {
offset: 0,
limit: 50,
},
..Default::default()
};
for (name, previous) in [
("cold", "unrelated_query"),
("warm", "group_57/controller_57"),
] {
let previous = parser.parse(previous);
group.bench_function(BenchmarkId::new("incremental", name), |b| {
b.iter_batched(
|| {
black_box(picker.fuzzy_search(&previous, None, options));
},
|()| black_box(picker.fuzzy_search(&parsed, None, options)),
BatchSize::PerIteration,
);
});
}
group.finish();
}

Expand Down
16 changes: 14 additions & 2 deletions crates/fff-core/src/file_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ use crate::index::layers::{LayerArenas, LayerId, LayerStack, SESSION_LAYER};
use crate::index::{BigramFilter, BigramOverlay};
use crate::query_tracker::QueryTracker;
use crate::scan::{ScanConfig, ScanJob, ScanSignals};
use crate::score::{fuzzy_match_and_score_files, fuzzy_match_byte_offsets_for_page};
use crate::score::{
FuzzyMatchCache, fuzzy_match_and_score_files, fuzzy_match_byte_offsets_for_page,
};
use crate::shared::{SharedFilePicker, SharedFrecency};
use crate::simd_path::ArenaPtr;
use crate::stable_vec::StableVec;
Expand Down Expand Up @@ -728,6 +730,8 @@ pub struct FilePicker {
enable_fs_root_scanning: bool,
enable_home_dir_scanning: bool,
git_recency_config: GitRecencyConfig,
// Cleared whenever files are added, restored or replaced.
fuzzy_cache: parking_lot::Mutex<Option<FuzzyMatchCache>>,
trace_span: tracing::Span,
trace_id: String,
}
Expand Down Expand Up @@ -873,6 +877,7 @@ impl FilePicker {
}

pub fn get_file_mut(&mut self, index: usize) -> Option<(ArenaPtr, &mut FileItem)> {
*self.fuzzy_cache.get_mut() = None;
self.sync_data.get_file_mut(index)
}

Expand Down Expand Up @@ -1113,6 +1118,7 @@ impl FilePicker {
enable_fs_root_scanning: options.enable_fs_root_scanning,
enable_home_dir_scanning: options.enable_home_dir_scanning,
git_recency_config: options.git_recency,
fuzzy_cache: parking_lot::Mutex::new(None),
trace_span,
trace_id,
})
Expand Down Expand Up @@ -1366,13 +1372,16 @@ impl FilePicker {
let arenas = self.sync_data.layer_arenas();
let overlay_ranges = self.sync_data.layers.file_ranges(files.len());

let mut cache = self.fuzzy_cache.lock().take();
let (items, scores, total_matched) = fuzzy_match_and_score_files(
files,
&context,
self.sync_data.base_count,
arenas,
&overlay_ranges,
&mut cache,
);
*self.fuzzy_cache.lock() = cache;
let match_byte_offsets =
fuzzy_match_byte_offsets_for_page(query, &items, max_typos, arenas);

Expand Down Expand Up @@ -1751,6 +1760,7 @@ impl FilePicker {
self.cache_budget.reset();
let mut previous = std::mem::replace(&mut self.sync_data, sync);
self.sync_data.adopt_overlays(&mut previous);
*self.fuzzy_cache.get_mut() = None;
previous
}

Expand Down Expand Up @@ -1894,7 +1904,7 @@ impl FilePicker {
) -> Option<(ArenaPtr, &mut FileItem)> {
let path = path.as_ref();
let index = self.sync_data.find_file_index(path, &self.base_path);
index.and_then(|i| self.sync_data.get_file_mut(i))
index.and_then(|i| self.get_file_mut(i))
}

/// Handle the event of certain file being modified or adds a neww file if it is not added
Expand Down Expand Up @@ -2018,6 +2028,8 @@ impl FilePicker {
self.sync_data.ensure_capacity(0, 1);
let parent_dir = self.sync_data.find_or_add_dir(&dir_rel)?;

*self.fuzzy_cache.get_mut() = None;

let chunked = self
.sync_data
.layers
Expand Down
3 changes: 3 additions & 0 deletions crates/fff-core/src/file_picker/layer_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ impl FilePicker {
/// overlays exist and [`Error::IndexBusy`] during a scan or post-scan indexing.
pub fn create_layer(&mut self, label: Option<&str>) -> Result<LayerId, Error> {
self.ensure_index_idle()?;
*self.fuzzy_cache.get_mut() = None;
let id = self.sync_data.create_layer(label)?;
debug!(layer = id, ?label, "Opened new index layer");

Expand Down Expand Up @@ -666,6 +667,7 @@ impl FilePicker {
) -> Result<usize, Error> {
let entries: Vec<IndexEntry<'a>> = entries.into_iter().collect();
self.reserve_index(entries.len(), entries.len())?;
*self.fuzzy_cache.get_mut() = None;
let added = self.sync_data.add_entries(&entries)?;
debug!(
added,
Expand All @@ -685,6 +687,7 @@ impl FilePicker {
self.ensure_index_idle()?;
let id = self.sync_data.layers.free_id().ok_or(Error::LayerLimit)?;
self.reserve_index(snapshot.files.len(), snapshot.dirs.len())?;
*self.fuzzy_cache.get_mut() = None;
let added = self.sync_data.attach_snapshot(id, snapshot, Attach::Import);
info!(layer = id, added, "Imported index layer");

Expand Down
Loading
Loading