nex_shift/native
mula.liu 7e3bf5efc1 perf: stop sampling when nothing is looking
Reported: "参考nex_squid的代码,进一步降低软件本身占用的系统资源." The
pattern worth copying out of nex_squid's `useSystemSnapshot` is that a
poll stops when nothing can see its answer. Shift had four places that
polled for the life of the process instead.

- `native/macos/drag-bridge.swift` — a separate tracked process polling at
  30 Hz forever, and allocating a CGEvent each pass to read a cursor
  position nothing wants while no button is held. A/B against the shipped
  0.1.11 binary: 20 ms CPU per 6 s idle is now 0 ms, while 12 s of holding
  the button still costs 30 ms either way, so a gesture is sampled exactly
  as finely as before and an idle Shift stops touching the CPU. It runs at
  10 Hz until the button goes down.
- `src-tauri/src/drag_bridge.rs` — the Windows gesture watch slept 33 ms
  unconditionally. An *enabled* ring keeps 33 ms, and not from
  conservatism: the loop has to observe the press to measure the drag
  threshold from where the button went down, so slowing it does not notice
  a gesture late, it never records it. Only a switched-off ring can afford
  a quarter second, since the one thing it waits for is the switch.
- `src-tauri/src/share.rs` — the discovery loop. Measured on the 0.1.11
  bundle: 0.22% CPU with ShiftDrop on, 0.03% with it off. Switching the
  feature off means "stop announcing", never "be deaf" — a silent copy
  still hears beacons so another machine can still find and send to it, and
  expiry must keep running or an hour-old peer pretends to be live forever.
  So the saving comes from waking less often while silent and from skipping
  bookkeeping when there is no peer to expire, not from probing less.
  Announce and sweep intervals are untouched, so discovery stays as fast.
  `a_silent_copy_still_knows_and_still_loses_peers` pins that distinction.
- `src/components/MainWindow.tsx` — the 30 s clock ticked for the life of
  the app while Shift sits parked in the menu bar with this window hidden,
  re-rendering a list nobody could see. It now exists only while the page is
  visible, and an empty library is not worth a render at all.

Co-Authored-By: Codex <noreply@openai.com>
2026-11-19 17:50:57 +08:00
..
macos perf: stop sampling when nothing is looking 2026-11-19 17:50:57 +08:00