on Windows, update far less often on filesystem changes. (#3601)

By increasing the window size for collecting filesystem events,
knowing that each event is processed in parallel, we might be lucky
and that already reduces the likelyhood of clashes.

It's an experiment though.

On Unix, run with:

`LOG_LEVEL=debug pnpm tauri dev --features adapt-to-windows`
This commit is contained in:
Sebastian Thiel 2024-04-25 07:16:41 +02:00
parent bb48dff72a
commit 74eb7bd397
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B
3 changed files with 19 additions and 1 deletions

View File

@ -63,6 +63,9 @@ features = [
"window-unmaximize"
]
[target."cfg(windows)".features]
gitbutler-watcher = { workspace = true, features = ["adapt-to-windows"] }
[lints.clippy]
all = "deny"
perf = "deny"
@ -70,6 +73,8 @@ correctness = "deny"
[features]
default = ["custom-protocol", "sentry", "devtools"]
## A forwarding to all crates that have windows-specific adjustments for testing on non-Windows.
adapt-to-windows = ["gitbutler-watcher/adapt-to-windows"]
devtools = ["tauri/devtools"]
# this feature is used used for production builds where `devPath` points to the filesystem

View File

@ -4,6 +4,11 @@ version = "0.0.0"
edition = "2021"
publish = false
[features]
default = []
## A trial to see if doing things differently on Windows helps with #3601
adapt-to-windows = []
[lib]
doctest = false

View File

@ -12,7 +12,11 @@ use tracing::Level;
/// The timeout for debouncing file change events.
/// This is used to prevent multiple events from being sent for a single file change.
const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(100);
const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(if cfg!(feature = "adapt-to-windows") {
2000
} else {
100
});
/// This error is required only because `anyhow::Error` isn't implementing `std::error::Error`, and [`spawn()`]
/// needs to wrap it into a `backoff::Error` which also has to implement the `Error` trait.
@ -44,6 +48,10 @@ pub fn spawn(
out: tokio::sync::mpsc::UnboundedSender<InternalEvent>,
) -> Result<()> {
let (notify_tx, notify_rx) = std::sync::mpsc::channel();
tracing::info!(
"Starting filesystem monitor on {worktree_path:?} with debounce of {:02}s",
DEBOUNCE_TIMEOUT.as_secs_f32()
);
let mut debouncer =
new_debouncer(DEBOUNCE_TIMEOUT, None, notify_tx).context("failed to create debouncer")?;