Repository navigation
perf(daemon): refresh before each request from native file watcher events - #217
Draft
sergej-koscejev wants to merge 9 commits into
Draft
sergej-koscejev wants to merge 9 commits into
sergej-koscejev wants to merge 9 commits into
Conversation
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 10, 2026
This was referenced Nov 11, 2026
sergej-koscejev
marked this pull request as draft
November 17, 2026 20:12
sergej-koscejev
force-pushed
the
perf/188-native-file-watcher
branch
from
November 17, 2026 20:39
adcf083 to
e6b3f43
Compare
sergej-koscejev
marked this pull request as ready for review
November 17, 2026 20:44
sergej-koscejev
marked this pull request as draft
November 18, 2026 14:18
The scenario takes the way it runs the CLI as a parameter, so another test can run it with different daemon options.
ExternalProjectRefresh kept what earlier refreshes saw and decided what changed since then. It now follows `one-kind`: - RefreshBaseline (Value) holds what a refresh saw. - externalChangePolicy.kt (Logic) decides which archives to refresh, which folders to load stored files for, and which runtimes to replace. - ExternalProjectRefresh (Adapter) does the VFS and MPS work. It keeps the baseline of the latest refresh as a private cache (`adapter-cache`). moduleRefresh.kt is split. moduleLocations.kt (Adapter) reads where modules are loaded from, now including the class paths of MPS-managed modules. moduleRefresh.kt (Adapter) keeps the VFS refresh functions. A refresh that throws now keeps the whole previous baseline. Before, it kept whatever parts it had updated before the failure.
…fresh The existing gate tests now queue their readers behind running exclusive work, so they still describe batches of readers queued before a refresh. The new test fails until the gate stops admitting readers that arrived during the refresh.
A reader that arrived while a refresh ran shared that refresh, so it could miss an external change made just before it arrived.
Twenty times in a row, for a project model and for a library model outside the project folder.
The daemon plugin registers a native file watcher that also runs in a headless application. Before MPS starts, the daemon copies fsnotifier from the MPS distribution into its workspace and makes it executable, because the generic distribution archive drops the executable bit. Without a binary for the platform it turns the watcher off. Refreshes still walk every folder.
With the native file watcher available, refreshes use its events. With the watcher turned off through the daemon's Java options, edits stay visible and every refresh walks the folders. Both tests fail until refreshes log their mode.
Logic and Values only; nothing calls them yet. assessFileWatcher decides from the watcher's signals whether a refresh can rely on its events, and planFolderRefresh splits the folders into those to walk and those to refresh from events.
Before each request, the daemon waits for the watcher to report a fence file, then refreshes known, watched folders from the watcher's events instead of walking them. It walks the folders when the watcher is not trusted; the daemon log names the mode and cost of each refresh. FolderRefresher (Adapter) refreshes the folders. It keeps the watcher's change count and the folders refreshed before as a private cache (`adapter-cache`).
sergej-koscejev
force-pushed
the
perf/188-native-file-watcher
branch
from
November 18, 2026 21:21
e6b3f43 to
4b17310
Compare
sergej-koscejev
marked this pull request as ready for review
November 18, 2026 21:21
sergej-koscejev
marked this pull request as draft
November 19, 2026 20:11
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.
Summary
Fixes #188
Before each request, the daemon refreshes known, watched folders from native file watcher (
fsnotifier) events. It walks the folders only when it cannot trust the watcher.Also:
HeadlessNativeFileWatcher, a secondpluggableFileWatcherthat stays on in a headless application. Before MPS starts, the daemon copiesbin/<os>/fsnotifierinto<workspace>/fsnotifier/and makes it executable. With no binary for the platform it turns the watcher off.MOPS_DAEMON_JAVA_OPTIONS=-Didea.filewatcher.disabled=trueturns it off by hand.Decisions the issue left open: the daemon copies
fsnotifier, not the CLI launcher, so daemon tests get the same watcher. The fence has its own watch root in the IDEA system directory. The startup walk is the first request's refresh, so the first request pays for it. After a watcher failure notification, every refresh walks until the daemon restarts.Changes since the first version of this PR
The refresh behaves the same except where a point below says otherwise. The changes follow the repo's rules for commits and design standards:
The history is rebuilt on
mainas nine commits with no merges. Tests come before the code that makes them pass.A refactor commit first splits
ExternalProjectRefreshas it is onmain, so that it followsone-kind:RefreshBaseline(Value): what a refresh saw (class paths, archive stamps, folders with stored files loaded).externalChangePolicy.kt(Logic): which archives to refresh, which folders to load stored files for, and which runtimes to replace, with unit tests inExternalChangePolicyTest.ExternalProjectRefresh(Adapter): the VFS and MPS work. It keeps the baseline of the latest refresh as a private cache (adapter-cache): without it, a refresh would refresh every archive, load every folder's stored files and replace every runtime.moduleRefresh.ktis split:moduleLocations.kt(Adapter) reads where modules are loaded from, now including the class paths of MPS-managed modules, andmoduleRefresh.kt(Adapter) keeps the VFS refresh functions.One behavior differs: a refresh that throws keeps the whole previous baseline. Before, it kept the parts it had updated before the failure.
WatchedFolderRefreshmixed policy, I/O and state. It is split into thedaemon.filewatcherpackage:assessFileWatcherandplanFolderRefresh, with unit tests inFolderRefreshPolicyTest.FolderRefresher,NativeFileWatcherProbe,FileWatcherFence,FileWatcherExecutableandexecuteFolderRefresh.FolderRefresherkeeps the watcher's change count and the folders refreshed so far as a private cache, and updates it only when a refresh finishes; without it, every folder is walked.WatcherAssessment,WatchCoverage,FolderRefreshPlan,FolderRefreshReportandFullWalkReason.Fence.Reported(coverage)), so the coverage is read only after a reported fence without a call-order contract.Every new or changed class has a kind word and a
Hides:line. Where a class breaks a rule, its KDoc says which rule and why:ProjectRequestGatebreaksone-kind.connascence-in-types, because they reach each other by name across the plugin class loader, asJavaParserreachesJavaParserBridge.adapter-cache: it keeps the watch roots and whether a failure was reported, because the platform tells it about them only through calls and notifications.DaemonWorkspace.fileWatcherDirnames thefsnotifier/directory.LibraryModelRefreshIntegrationTestis now a smoke test, so the full tier also runs it on macOS and Windows.Two log reasons changed:
the file watcher did not report the fence in timereplaces… within 2000 ms.the file watcher reported a failurenow addsor its restarts cannot be counted, because a missing restart counter gives the same result as a reported failure.Where to look
ProjectRequestGate.run: the batch rule. Under concurrent reads there are more refreshes, and each one can wait for the fence (up to about 300 ms on macOS right after an edit).assessFileWatcherinfilewatcher/folderRefreshPolicy.kt: the trust conditions and their order. Look also at which change count is kept when a check fails early.ExternalProjectRefresh.refresh: the order of the refresh steps and which baseline each step compares with. Its baseline andFolderRefresher's cache are written only when the refresh finishes. It is an Adapter for "MPS's view of the project's files on disk", though it drives several platform services (VFS,StoreReloadManager,ReloadManager,ClassLoaderManager).Left for later: #298 (runtime checks on Windows, Linux aarch64 and the watcher failure path) and #301 (
ClassPathFingerprintsunderadapter-cache).Evidence
Fence (
ExternalProjectRefreshSemanticsTest): 20 times in a row, the test renames a node in a model file, refreshes right away, and reads the node. It runs once for a project model and once for a library model outside the project folder. On macOS and Linux x86-64, it also asserts that every refresh after the first used watcher events.Before: with
awaitFencereturningREPORTEDwithout waiting, both tests fail atedit 0 is visible after the refresh.After: both pass (MPS 2026.1.2, macOS arm64).
Gate (
ProjectRequestGateTest):a reader arriving during a refresh waits for its own refresh.Before: fails on
main.After: passes.
Watcher on and off (
LibraryModelRefreshIntegrationTest, through the installed CLI): with the watcher on, the log saysusing file watcher events. With-Didea.filewatcher.disabled=true, edits stay visible, the log saysa full walk because the file watcher is not operational, and no refresh used watcher events. Both pass on 2026.1.1.Suites:
checkpasses on macOS arm64::daemon:test(499),:cli:test(385),:protocol:test(111),:architecture-tests:testand the CLI integration tests for each MPS version. Every commit compiles and passesdetektMain.Per-request cost (measured on the first version of this PR, which has the same refresh logic, not measured again): a copy of MPS-extensions with MPS 2024.1.6 (260 modules, 51,757 files, built), macOS arm64, on a busy machine.
main/ watcher offmops list --depth 0, wall time, 25 runs, medianMerge Danger
Blast Radius: daemon-wide
Every daemon now starts an
fsnotifierprocess. Whether a request sees external changes now depends on the fence and the trust checks. If a check is wrong, a request misses an external edit and nothing reports it. The tests assert watcher use only on macOS and Linux x86-64; #298 lists what has not run.