mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Fix high CPU usage due to inotify watch triggering itself (#5905)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
225e845021
commit
acd3a5b7a5
@ -204,6 +204,10 @@ impl Watcher {
|
|||||||
let event = event
|
let event = event
|
||||||
.map_err(|err| eco_format!("failed to watch dependencies ({err})"))?;
|
.map_err(|err| eco_format!("failed to watch dependencies ({err})"))?;
|
||||||
|
|
||||||
|
if !is_relevant_event_kind(&event.kind) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Workaround for notify-rs' implicit unwatch on remove/rename
|
// Workaround for notify-rs' implicit unwatch on remove/rename
|
||||||
// (triggered by some editors when saving files) with the
|
// (triggered by some editors when saving files) with the
|
||||||
// inotify backend. By keeping track of the potentially
|
// inotify backend. By keeping track of the potentially
|
||||||
@ -224,7 +228,17 @@ impl Watcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
relevant |= self.is_event_relevant(&event);
|
// Don't recompile because the output file changed.
|
||||||
|
// FIXME: This doesn't work properly for multifile image export.
|
||||||
|
if event
|
||||||
|
.paths
|
||||||
|
.iter()
|
||||||
|
.all(|path| is_same_file(path, &self.output).unwrap_or(false))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
relevant = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we found a relevant event or if any of the missing files now
|
// If we found a relevant event or if any of the missing files now
|
||||||
@ -234,19 +248,11 @@ impl Watcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether a watch event is relevant for compilation.
|
|
||||||
fn is_event_relevant(&self, event: ¬ify::Event) -> bool {
|
|
||||||
// Never recompile because the output file changed.
|
|
||||||
if event
|
|
||||||
.paths
|
|
||||||
.iter()
|
|
||||||
.all(|path| is_same_file(path, &self.output).unwrap_or(false))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match &event.kind {
|
/// Whether a kind of watch event is relevant for compilation.
|
||||||
|
fn is_relevant_event_kind(kind: ¬ify::EventKind) -> bool {
|
||||||
|
match kind {
|
||||||
notify::EventKind::Any => true,
|
notify::EventKind::Any => true,
|
||||||
notify::EventKind::Access(_) => false,
|
notify::EventKind::Access(_) => false,
|
||||||
notify::EventKind::Create(_) => true,
|
notify::EventKind::Create(_) => true,
|
||||||
@ -261,7 +267,6 @@ impl Watcher {
|
|||||||
notify::EventKind::Other => false,
|
notify::EventKind::Other => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// The status in which the watcher can be.
|
/// The status in which the watcher can be.
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user