Conversation
HgProcessOutputReader.Read polled for the reader threads every 100 ms, so every hg call took at least ~220 ms even when hg finished in 140 ms. The readers now signal a CountdownEvent and Read waits on it, keeping the 100 ms interval only for the cancellation and inactivity-timeout checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rmunn
approved these changes
Oct 2, 2026
rmunn
left a comment
Contributor
There was a problem hiding this comment.
This will definitely be a speed improvement; I had wondered why all calls to hg.exe or chg seemed to take 100ms, and now it's clearer why. This will definitely be an improvement.
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.
should improve run time for most hg commands and improve CI by around 5min
AI summary
HgProcessOutputReader.Readchecked whether hg's output reader threads had finished by sleeping 100 ms between checks. Every hg call therefore took at least ~220 ms, even when hg itself finished in 140–190 ms.The reader threads now signal a
CountdownEventwhen their stream closes, andReadwaits on it. The wait returns as soon as both streams close. The 100 ms timeout on the wait is kept only to check for cancellation and the inactivity timeout, which behave as before. The event is disposed whenReadreturns; ifReadhas already given up (timeout or cancel), the readers ignore the resultingObjectDisposedException. Waiting on the event also gives the reader threads'Resultsa memory barrier, which the old polling loop didn't have.Measured (median of 20 runs, Windows, a small repo):
HgRunnerbeforeHgRunnerafterversionstatuslog -r tiptipThe LibChorus.Tests run makes about 5,500 hg calls, so this should take roughly 4–6 min off its ~26 min on Windows. It also speeds up every hg call during a real Send/Receive.
Test plan
HgProcessReaderTestsandProcessStreamTestspass locally (they cover timeout and cancellation), as doHistoryTestsHgRunner.Runagainst launching hg.exe directly (table above)🤖 Generated with Claude Code
This change is