-
Notifications
You must be signed in to change notification settings - Fork 1.2k
working_copy: avoid "empty" fsmonitor saves #10049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jstasiak
wants to merge
1
commit into
jj-vcs:main
Choose a base branch
from
jstasiak:optimize-fsmonitor-empty-saves
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+47
−14
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -958,6 +958,7 @@ fn file_state(metadata: &Metadata) -> Result<Option<FileState>, MtimeOutOfRange> | |
| struct FsmonitorMatcher { | ||
| matcher: Option<Box<dyn Matcher>>, | ||
| watchman_clock: Option<crate::protos::local_working_copy::WatchmanClock>, | ||
| should_update_watchman_clock: bool, | ||
| } | ||
|
|
||
| /// Settings specific to the tree state of the [`LocalWorkingCopy`] backend. | ||
|
|
@@ -1303,11 +1304,11 @@ impl TreeState { | |
|
|
||
| let sparse_matcher = self.sparse_matcher(); | ||
|
|
||
| let fsmonitor_clock_needs_save = self.fsmonitor_settings != FsmonitorSettings::None; | ||
| let mut is_dirty = fsmonitor_clock_needs_save; | ||
| let mut is_dirty = false; | ||
| let FsmonitorMatcher { | ||
| matcher: fsmonitor_matcher, | ||
| watchman_clock, | ||
| should_update_watchman_clock, | ||
| } = self | ||
| .make_fsmonitor_matcher(&self.fsmonitor_settings) | ||
| .await?; | ||
|
|
@@ -1321,8 +1322,10 @@ impl TreeState { | |
| UnionMatcher::new(fsmonitor_matcher, force_tracking_matcher), | ||
| ); | ||
| if matcher.visit(RepoPath::root()).is_nothing() { | ||
| // No need to load the current tree, set up channels, etc. | ||
| self.watchman_clock = watchman_clock; | ||
| if should_update_watchman_clock { | ||
| is_dirty |= self.watchman_clock != watchman_clock; | ||
| self.watchman_clock = watchman_clock; | ||
| } | ||
| return Ok((is_dirty, SnapshotStats::default())); | ||
| } | ||
|
|
||
|
|
@@ -1412,11 +1415,15 @@ impl TreeState { | |
| // Since untracked paths aren't cached in the tree state, we'll need to | ||
| // rescan the working directory changes to report or track them later. | ||
| // TODO: store untracked paths and update watchman_clock? | ||
| if (stats.untracked_paths.is_empty() && stats.invalid_utf8_paths.is_empty()) | ||
| || watchman_clock.is_none() | ||
| // A failed monitor query has no clock and causes a full scan. Clear the | ||
| // old clock after that scan even if it found untracked paths. | ||
| if should_update_watchman_clock | ||
| && ((stats.untracked_paths.is_empty() && stats.invalid_utf8_paths.is_empty()) | ||
| || watchman_clock.is_none()) | ||
| { | ||
| is_dirty |= self.watchman_clock != watchman_clock; | ||
| self.watchman_clock = watchman_clock; | ||
| } else { | ||
| } else if should_update_watchman_clock { | ||
| tracing::info!("not updating watchman clock because there are untracked files"); | ||
| } | ||
| Ok((is_dirty, stats)) | ||
|
|
@@ -1448,6 +1455,12 @@ impl TreeState { | |
| }); | ||
| } | ||
| }; | ||
| // Do not advance the clock when the monitor reports no changed paths. | ||
| // This avoids rewriting the tree state just to save the new clock. | ||
| // Reusing the older clock may make a later query do more work, but it | ||
| // cannot omit changes. | ||
| let should_update_watchman_clock = | ||
| !matches!(&changed_files, Some(files) if files.is_empty()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| let matcher: Option<Box<dyn Matcher>> = match changed_files { | ||
| None => None, | ||
| Some(changed_files) => { | ||
|
|
@@ -1485,6 +1498,7 @@ impl TreeState { | |
| Ok(FsmonitorMatcher { | ||
| matcher, | ||
| watchman_clock, | ||
| should_update_watchman_clock, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: It seems slightly easier to follow nested
ifs rather than combining multiple&&and||conditions.