Skip to content

reduce background file operations for projects on remote filesystems - #18059

Merged
kevinushey merged 6 commits into
mainfrom
feature/remote-filesystem-optimizations
Jun 26, 2026
Merged

kevinushey merged 6 commits into
mainfrom
feature/remote-filesystem-optimizations

Conversation

@kevinushey

@kevinushey kevinushey commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds an option to reduce background file operations for projects located on network or remote filesystems, improving responsiveness on slow drives -- a long-standing pain point (see #10417).

When reduction is active for a project, RStudio:

  • skips registering the recursive project file monitor (which also stops driving code indexing, the Files pane's live refresh, and version-control status updates), and
  • short-circuits the check_for_external_edit stat checks.

Configuration

  • Global: Tools > Global Options > General > Advanced -> "Reduce background file operations on network and remote drives" (default on).
  • Per-project: Project Options > General -> tri-state ((Default) / Yes / No), overriding the global preference. This override is a user-specific, project-local preference ("local": true in the prefs schema), stored per-user under .Rproj.user rather than in the shared .Rproj file -- so it is not committed to version control, since whether a project lives on a slow/remote mount is a per-user, per-machine fact.

The resolver precedence is: per-project Yes/No wins; otherwise the global preference, which in automatic mode applies only when the project is detected to live on a remote filesystem. Because the per-project override is consulted during project startup -- before the project preference layer is initialized -- the backend reads it directly from the local prefs file (.Rproj.user/<ctx>/rstudio-prefs.json).

Detection

core::system::isRemotePath():

  • Windows: PathIsNetworkPathW + GetDriveTypeW/DRIVE_REMOTE
  • macOS: statfs + MNT_LOCAL
  • Linux: statfs f_type magic numbers (NFS / CIFS / SMB / FUSE / ...)

The detection result is cached per project, since statfs() on a hung remote mount can block.

A one-time informational console message (via R message()) is shown when reduction is active for a project.

Also included (separable)

This branch also relocates the desktop "GPU exclusion list" / "GPU driver bug workarounds" settings from the General > Advanced preferences pane to Command Palette commands (toggleGpuExclusionList, toggleGpuDriverBugWorkarounds), to free space in the pane. Committed alongside the feature here; can be split out if preferred.

Verification

  • macOS detection branch and all touched session code compile locally; ant javac is clean.
  • The Windows (isRemotePath) and Linux (statfs) branches have not been compiled locally and need a CI/Windows/Linux build.
  • No automated tests yet; a unit test for the precedence resolution is a possible follow-up.

Addresses #10417.

@kevinushey kevinushey added this to the 2026.07 (Pacific Dogwood) milestone Jun 24, 2026
The two new Messages-based constants (gpuSettingChanged*, reduceRemoteFilesystemOperationsText) were added to the _en properties files but not _fr. GWT requires every key of a Messages interface to resolve in every supported locale, so generating the _fr variant failed the GWT compile on all platforms.
@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

🍎 macOS Desktop E2E · ARM64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
410 0 10 0
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · macos-26 ARM64 · commit 3f3573a6d91fcdaf364e5a5429c7d3513485525c · Run #188

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

🪟 Windows Desktop E2E · Server 2025 x64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
409 0 13 0
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · Windows Server 2025 x64 · commit 3f3573a6d91fcdaf364e5a5429c7d3513485525c · Run #188

@gtritchie

Copy link
Copy Markdown
Member

Code review findings

Actionable items from an automated multi-agent review (code quality, error handling, comments, test coverage). The detection logic, magic-number values, GPU-command relocation, and the per-project local-prefs read/write wiring were all verified correct and are not listed here.

Important

  1. src/cpp/session/projects/SessionProjectContext.cpp:264-313 (called per-poll from src/cpp/session/modules/SessionSource.cpp:1134) — reduceRemoteFilesystemOperations() does exists() + readStringFromFile() + json::Value::parse() on every call. Only the isRemotePath() detection is cached (remoteFilesystemChecked_), not the file read or the resolved value, and checkForExternalEdit fires on window focus and file-change events. By default scratchPath_ (.Rproj.user/<ctx>) lives on the same remote mount the feature exists to stay off, so the short-circuit meant to avoid two slow stats itself performs a stat + open + read + parse on the slow drive each time. The "read directly because the pref layer isn't initialized yet" rationale only applies to the startup()/initialize() calls; at runtime UserPrefsProjectLayer is initialized and already caches the override. Fix: cache the resolved value (the per-project override only changes via a dialog apply that already forces a restart), or resolve through the pref layer at runtime.

  2. src/gwt/.../prefs/views/GeneralPreferencesPane.java:278 + onApply, vs. src/cpp/session/projects/SessionProjectContext.cpp:469 and :689 — toggling the global pref mid-session is inconsistent: the external-edit check (live resolver) starts/stops short-circuiting immediately, but hasFileMonitor_ and the onDeferredInit monitor subscription are decided only once at startup, so monitoring/indexing keeps its startup state until restart. The global checkbox sets no restart requirement, while the per-project control (ProjectGeneralPreferencesPane.java:260-262) correctly forces one. Fix: have the global pref mark a session restart requirement for consistency, or document the asymmetry as intended.

Medium (error handling)

  1. src/cpp/session/projects/SessionProjectContext.cpp:286-294 — a json::Value::parse() failure (corrupt/truncated rstudio-prefs.json) and a parsed-but-non-object value both fall through to the global-pref fallback with no log, while the read failure at :282 is logged. This diverges from the loadPrefsFromFile precedent at src/cpp/session/prefs/PrefLayer.cpp:136-141, which converts a parse failure into a logged LOAD_ERROR. A corrupt local prefs file would silently drop the user's explicit per-project setting with no breadcrumb. Fix: LOG_ERROR on parse failure to match the rest of the prefs subsystem.

  2. src/cpp/core/system/PosixSystem.cpp:1046-1047 (macOS) and :1056-1057 (Linux) — every statfs() failure (EACCES, EIO/ETIMEDOUT on a hung mount, ENOTCONN on a stale NFS handle) collapses to a silent return false, indistinguishable in the logs from a genuine "local disk" answer. The sibling isReadOnly() at :1012-1032 is the in-file template: it logs unexpected errnos via systemError(errno, ERROR_LOCATION) with the path attached. The return false default is correct (fail-safe); the gap is diagnostic. Fix: log the unexpected errno before returning false so a "optimization never activates on my NFS share" report is debuggable.

Suggestions

  1. src/cpp/core/system/PosixSystem.cpp:1063 (magic at :139, annotated // sshfs, rclone, etc.) — FUSE is a mechanism, not inherently remote: local FUSE mounts (ntfs-3g, exfat-fuse, encfs/gocryptfs, AppImage/squashfuse, bindfs, mergerfs) all report FUSE_SUPER_MAGIC and would be misclassified as remote. Because the global default is true, affected users silently get reduced operations automatically. Fix: narrow the classification, or change the comment to acknowledge the deliberately conservative over-broad match instead of implying FUSE == remote.

  2. No automated tests are included. The precedence decision is the most logic-dense, platform-independent, regression-prone piece and is currently untestable because it mixes disk I/O, the global-pref singleton, and the decision. Fix: extract a pure free function resolveReduceRemoteFilesystemOperations(localOverride, globalPref, remoteDetected) and add cases to src/cpp/session/projects/SessionProjectsTests.cpp (following the existing resolveWrittenEditorTheme precedent — auto-globbed, no CMake change), covering: local override wins over global+detection in both directions, global-off short-circuits, and global-on gated by detection. Split the local-prefs parse into a helper returning boost::optional<bool> to test the malformed/absent/wrong-type paths. A cheap isRemotePath(FilePath()) empty-path test guards the early return.

  3. src/cpp/core/system/PosixSystem.cpp:60-65 — the constants SMB2_MAGIC_NUMBER and CIFS_MAGIC_NUMBER are not the canonical <linux/magic.h> names (SMB2_SUPER_MAGIC / CIFS_SUPER_MAGIC), so their #ifndef guards never match the system header and the local fallback #defines are always used — contradicting the "Most of these are provided by <linux/magic.h>" framing for those two (values are identical, so behavior is unaffected). Fix: rename to the canonical *_SUPER_MAGIC names, or note that SMB2/CIFS are intentionally defined locally. Separately, src/cpp/core/include/core/system/System.hpp:286-288 gives only a Windows example ("UNC path or mapped network drive") for a function implemented on all three platforms; consider mentioning NFS/SMB on macOS/Linux.

- cache the resolved reduce-remote-filesystem decision so checkForExternalEdit
  no longer reads/parses the local prefs file and probes the mount per poll
- force a session restart when the global preference is toggled, matching the
  per-project control
- log local-prefs parse failures and unexpected statfs errnos
- extract pure resolveReduceRemoteFilesystemOperations /
  parseReduceRemoteFilesystemOperationsOverride helpers and add unit tests
- rename SMB2/CIFS magic numbers to the canonical *_SUPER_MAGIC names and
  clarify the FUSE over-match and isRemotePath docs

Addresses #10417.
@kevinushey
kevinushey merged commit e9138d7 into main Jun 26, 2026
15 checks passed
@kevinushey
kevinushey deleted the feature/remote-filesystem-optimizations branch June 26, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants