Repository navigation
docs(fsmonitor): correct the sweep's cost model after the batched lsof - #3852
Merged
Merged
Conversation
The internal sweep after `wt remove` ran one `lsof -a -p <pid>` per candidate PID, and the candidate set is machine-wide: every repo whose worktrees have been touched contributes a `git fsmonitor--daemon`. At ~50 ms a spawn that appended `N x 50 ms` before exit, while the shell wrapper waited on the process. `lsof -p` takes a comma-separated PID list, so one call covers the whole set. `daemons_from_lsof_batch` splits the `-F` output back into per-PID records on the `p<pid>` lines and hands each to the existing classifier, so orphan classification is unchanged. Lines outside a parsable record are dropped rather than attached to a neighbour: crediting one process's socket to another would reap a live daemon. Exit status goes unchecked here. With a multi-PID set `lsof` reports failure when any one PID vanished mid-scan, while the survivors' records on stdout stay complete; a vanished PID emits no record and is never classified.
main landed the same optimization in a0c1b66 ("perf(fsmonitor): resolve all daemons in one lsof spawn"), so the branch's `src/git/fsmonitor.rs` implementation is dropped in favour of main's. Main's is the better of the two: it asks `lsof` for `-F pn` rather than relying on the `p` field being emitted unrequested, and its splitter streams records instead of buffering every one. What main left undone survives: - The two doc sites still described the old per-daemon `lsof`, promising `N x 50 ms` of post-output latency that no longer happens. - `daemons_from_batched_lsof` handles lines that sit under no parsable `p` line, and says so in a comment, but nothing pinned it.
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
The docs now match the batched sweep — enumerate_daemons is a pgrep plus one lsof -a -p <list>, and the debug string is quoted verbatim. The new test's premise checks out against daemons_from_batched_lsof: the leading nfsmonitor--daemon.ipc and the one under pBAD both land with no record open, so pid 301's record holds only n->0x1 and daemon_from_lsof_stdout drops it for want of IPC_SOCKET_NAME — misattributing either line would have made 301 a socket-less class-1 orphan. cargo test --lib git::fsmonitor::tests::batched passes locally (4/4).
One thing the rewrite tightened past what the code does: the enumeration is two spawns, but the exit delay isn't. See the inline note on run_internal_sweep.
Enumeration is the two spawns; the reap adds a `git worktree list` for any live daemon and a bounded SIGTERM→SIGKILL wait for a classified orphan. Both are flat in the daemon count, so the claim the rewrite was making still holds — it just wasn't the whole exit delay.
worktrunk-bot
approved these changes
Aug 18, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
#3581 batched the fsmonitor sweep into a single
lsofover the whole PID set, but left two places still describing the per-daemon cost it removed. Both now read as ifwt removestill paysN × 50 msafter its last message:run_internal_sweep's docstring insrc/commands/process.rs— "one sequential ~50mslsofper daemon (measured: 115 daemons → ~5.8s of post-output latency)"benches/CLAUDE.md§ Recordingwt remove/wt step prunestaging — the same model, plus awt-perfrecipe pointing atlsof -a -p …child spans that a batched sweep no longer producesBoth are rewritten to what the sweep now does: one
pgrepplus onelsof, flat in the machine-wide daemon count. The docstring also names the rest of the exit delay, which the old text attributed entirely to enumeration — agit worktree listfor any live daemon, and aSIGTERM→SIGKILLwait bounded byREAP_KILL_DEADLINEfor a classified orphan. Both are flat in the daemon count too. The debug line the benches doc quotes is updated to matchenumerate_daemonsverbatim.Also adds
batched_lsof_drops_lines_outside_a_parsable_record, covering socket lines with no parsablepline above them — leading output, and lines under an unparsablepBAD. Attaching those to a neighbouring record would fabricate a class-1 orphan and signal a live daemon. The neighbouring tests cover per-PID splitting, vanished PIDs, and empty output, but not this one.