From 623f77e0973085bf7a7eea34278679cf751b964b Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 4 Jan 2022 04:00:06 -0800 Subject: [PATCH] minor perf optimization: remove this loop on macOS --- src/feature_flags.zig | 2 ++ src/watcher.zig | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/feature_flags.zig b/src/feature_flags.zig index b9bcf3bab9..42c1d17828 100644 --- a/src/feature_flags.zig +++ b/src/feature_flags.zig @@ -84,3 +84,5 @@ pub const disable_compression_in_http_client = false; // Time (mean ± σ): 306.7 ms ± 6.1 ms [User: 31.7 ms, System: 269.8 ms] // Range (min … max): 299.5 ms … 318.8 ms 10 runs pub const use_libgit2 = true; + +pub const atomic_file_watcher = env.isLinux; diff --git a/src/watcher.zig b/src/watcher.zig index 33d5aa9a30..35606f697b 100644 --- a/src/watcher.zig +++ b/src/watcher.zig @@ -532,10 +532,12 @@ pub fn NewWatcher(comptime ContextType: type) type { comptime copy_file_path: bool, ) !void { if (this.indexOf(hash)) |index| { - // On Linux, the file descriptor might be out of date. - if (fd > 0) { - var fds = this.watchlist.items(.fd); - fds[index] = fd; + if (comptime FeatureFlags.atomic_file_watcher) { + // On Linux, the file descriptor might be out of date. + if (fd > 0) { + var fds = this.watchlist.items(.fd); + fds[index] = fd; + } } return; }