diff --git a/crates/ide-index/src/worker.rs b/crates/ide-index/src/worker.rs
index a454c99c1..db50ee589 100644
--- a/crates/ide-index/src/worker.rs
+++ b/crates/ide-index/src/worker.rs
@@ -46,6 +46,20 @@ const SNAPSHOT_DELAY: Duration = Duration::from_millis(50);
const SNAPSHOT_EVERY: Duration = Duration::from_secs(10);
#[cfg(test)]
const SNAPSHOT_EVERY: Duration = Duration::ZERO;
+/// A refresh waits this many times as long as the last one took, up to [`SNAPSHOT_EVERY_MAX`]: in
+/// a project of 160 000 files a write takes seconds and holds the disk, and a build writing into
+/// it would otherwise have it rewritten every few seconds for minutes (#7363).
+const SNAPSHOT_COST_FACTOR: u32 = 30;
+const SNAPSHOT_EVERY_MAX: Duration = Duration::from_secs(300);
+
+/// The shortest gap after a snapshot write that took `cost` (none in tests, as [`SNAPSHOT_EVERY`]).
+fn snapshot_gap(cost: Duration) -> Duration {
+ if cfg!(test) { SNAPSHOT_EVERY } else { gap_after(cost, SNAPSHOT_EVERY) }
+}
+
+fn gap_after(cost: Duration, every: Duration) -> Duration {
+ every.max(cost.saturating_mul(SNAPSHOT_COST_FACTOR).min(SNAPSHOT_EVERY_MAX))
+}
/// A subtree scan with fewer files to parse runs without showing "Indexing" (see `scan`).
const QUIET_SCAN_FILES: usize = 200;
pub(crate) const MAX_RECENT: usize = 50;
@@ -87,8 +101,9 @@ pub(crate) struct Shared {
idle: Condvar,
/// Coalesced post-update snapshot refresh.
snapshot_due: Mutex