Skip to content

High CPU usage in LinearMouse 0.11.4 due to broad FSEvents configuration watches #1368

Closed

Description

@mhaslinsky

Description

LinearMouse 0.11.4 consumes 18% to 51% of a CPU core on macOS 26.6.1 while the mouse event thread is idle. This load recurs within 10 seconds of relaunching the application, indicating it is not a stale event backlog.

Active configuration file:
~/.config/LinearMouse/linearmouse.json

The FSEvents stream watches both ~/.config and ~/Library/Application Support. Unrelated writes under these roots force LinearMouse to canonicalize every event path on the main thread before filtering.

Sample Evidence

An 8-second sample of the original 0.11.4 process captured 2,110 of 6,863 main-thread samples (about 31%) in the FSEvents callback.

A second sample from a fresh 0.11.4 process captured 2,013 of 8,740 main-thread samples (about 23%) in the callback, including 332 readlink and 73 lstat samples. The mouse event thread remained idle in both traces.

PR #1209 introduced the broad watcher. In FileWatcher.rootPaths(for:), the watch root for a configuration file defaults to its parent directory. For ~/.config/LinearMouse/linearmouse.json, this expands the watch to the entirety of ~/.config. Additionally, ConfigurationState.startHotReload() supplies both candidate paths, adding all of ~/Library/Application Support when the alternate configuration directory is missing.

Proposed Fix and Validation

The proposed patch resolves this by:

  1. Supplying only the active configurationPath to FileWatcher.
  2. Watching the existing configuration directory directly instead of its parent.
  3. Falling back to the nearest existing ancestor only when the configuration directory is missing, then rebinding upon recreation.

The focused FileWatcherTests suite passed all tests (including directory deletion and recreation), and the full Xcode test run completed with all 561 test cases passing.

In an 8-second sample of the patched build with Accessibility enabled, the main thread was idle for 6,824 of 6,879 samples. There were no FileWatcher, FSEvents, readlink, or lstat frames. The signed 0.11.2 release remains at 0.0% CPU as a practical workaround.

The tested 3-file patch is ready to submit.

Environment

  • LinearMouse 0.11.4
  • macOS 26.6.1 (25G76)
  • Apple silicon
  • Active configuration: ~/.config/LinearMouse/linearmouse.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions