feat: use double-buffer for winapi observer#1152
Merged
BoboTiG merged 2 commits intogorakhargosh:masterfrom Jan 7, 2026
Merged
feat: use double-buffer for winapi observer#1152BoboTiG merged 2 commits intogorakhargosh:masterfrom
BoboTiG merged 2 commits intogorakhargosh:masterfrom
Conversation
This improves the performance of the winapi observer by using a second thread and by using double-buffering. The time window for events to be lost due to processing outside the ReadDirectoryChangesW() call should be smaller. The events buffer is reused rather than creating a new one on every call.
Collaborator
|
Thanks @nascheme! I guess there is at least one test to adapt on Windows, cf the failure(s) on the CI. 👍 for me when the CI will be green (take care of Windows only, we already know the Linux & macOS tests are passing). |
Contributor
Author
|
Should be fixed with my latest commit (need a short sleep before ending the |
This comment was marked as off-topic.
This comment was marked as off-topic.
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.
This improves the performance of the winapi observer by using a second thread and by using double-buffering.
The
read_directory_changes()function was replaced with a classDirectoryChangeReader()that takes care of reading the Windows handle. TheReadDirectoryChangesW()calls are made in a separate background thread and data returned is copied into a separate queue, to be processed with_parse_event_buffer()in a separate thread.The time window for events to be lost due to processing outside the
ReadDirectoryChangesW()call should be smaller. The events buffer is reused rather than creating a new one on every call.The management of the Windows handle is encapulated in the
DirectoryChangeReader()class and it takes care of waking the background thread, cleanly closing the handle and cleaning up the thread.This partially addresses GH-1019. However, a better fix would use either overlapped IO or completion ports. However, that would be a more complex change.