Skip to content

Reduce monitoring overhead in Cleanmeter - #96

Open
saadah7 wants to merge 1 commit into
mainfrom
codex/cleanmeter-performance-part1
Open

saadah7 wants to merge 1 commit into
mainfrom
codex/cleanmeter-performance-part1

Conversation

@saadah7

@saadah7 saadah7 commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Reduce sidecar overhead from PresentMon row parsing, debug diagnostics, packet writes, and forced garbage collection.
  • Send live sensor readings to Settings while visible and replay the latest snapshot on open. Keep the overlay updating and use indexed sensor lookups.
  • Limit display enumeration to startup and event-triggered polling bursts.

Verification

  • 198 Vitest, 42 HardwareMonitor, and 46 Rust tests passed. ESLint and the frontend production build passed.
  • The standalone TypeScript check reports the same five errors on main and this branch.
  • A five-minute synthetic replay matched readings and reduced allocations by 42%. An unelevated 90-second desktop sample showed median working set rising from 94.91 to 96.30 MiB.
  • An elevated Windows run displayed live sensor readings and verified two overlay hotkey cycles. Native tray reopen, physical display changes, sleep/resume, and a same-scene borderless game comparison remain open.

Notion task

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The changes update hardware polling and PresentMon diagnostics, route retained sensor snapshots between Tauri webviews, revise sensor lookup behavior, and limit overlay display polling to event-triggered bursts.

Changes: Hardware data polling

Layer / File(s) Summary
Hardware status polling and serialization
HardwareMonitor/HardwareMonitor/Monitor/MonitorPoller.cs, HardwareMonitor/HardwareMonitor/SharedMemory/SharedMemory.cs, HardwareMonitor/HardwareMonitor/HardwareMonitor.csproj
Status serialization reuses shared options, stream writes truncate before writing, sensor NaN values become zero, and periodic forced garbage collection is removed. Hardware read progress uses ReadStage; the project sets System.GC.ConserveMemory to 5.
PresentMon row parsing and diagnostics
HardwareMonitor/HardwareMonitor/PresentMon/PresentMonPoller.cs, HardwareMonitor/HardwareMonitor.Tests/PercentileLowWiringTests.cs
PresentMon checks row length before splitting matching rows. Diagnostic snapshots, counters, and foreground-change logs are collected only when Debug logging is enabled. The wiring test covers short rows and app-picker behavior.

Tauri sensor delivery and overlay controls

Layer / File(s) Summary
Snapshot retention and event routing
tauri-app/src-tauri/src/pipe_client.rs, tauri-app/src-tauri/src/lib.rs
The app retains sensor snapshots and publishes sensor events to the overlay and, when visible, the settings webview. Disconnects clear the retained snapshot.
Settings snapshot requests and subscriptions
tauri-app/src-tauri/src/commands.rs, tauri-app/src-tauri/src/lib.rs, tauri-app/src-tauri/src/tray.rs, tauri-app/src-tauri/src/pipe_client.rs, tauri-app/src/hooks/useSensorData.ts, tauri-app/src/lib/tauri.ts, tauri-app/src/App.tsx, tauri-app/src/OverlayApp.tsx
Settings display, focus, and resize paths request or replay settings snapshots. The settings and overlay webviews subscribe to separate sensor events.
Native overlay toggle and sensor-data behavior
tauri-app/src-tauri/src/commands.rs, tauri-app/src-tauri/src/lib.rs, tauri-app/src/lib/tauri.ts, tauri-app/src/stores/settings-store.ts
The native toggle command inverts overlay visibility when it can read the current state. The store uses the command outside browsers and allows callers to suppress first-data overlay display.

Sensor lookup

Layer / File(s) Summary
Sensor identifier and frametime lookup
tauri-app/src/lib/utils.ts, tauri-app/src/lib/utils.test.ts
findSensorById indexes readonly sensor arrays and keeps the first match. findFrametimeSensor prefers the exact PresentMon identifier and otherwise uses a case-insensitive name or identifier match. Tests cover both helpers.
Sensor selection and display lookups
tauri-app/src/hooks/useSensorData.ts, tauri-app/src/stores/settings-store.ts, tauri-app/src/lib/gpu.ts, tauri-app/src/components/overlay/FpsSection.tsx
Frametime selection, GPU sensor resolution, and FPS and percentile-low lookups use the shared helpers. Existing fallback behavior remains in place where described.

Overlay display polling

Layer / File(s) Summary
Polling bursts and display-signal tests
tauri-app/src/lib/overlay-displays.ts, tauri-app/src/lib/overlay-displays.test.ts
Display polling runs immediately and at the configured interval for up to 60 seconds. Initialization, resize, visibility, and DPI changes start or restart polling. Tests cover these signals and cleanup.
Merge Risk: Low · up to a5718

After a display resolution change at the same DPI, the overlay may stay positioned against the old monitor geometry until a resize, visibility change, or DPI change triggers a refresh. The rest of the change looks safe to merge. Consider adding a display-change trigger, or validating on a physical resolution change, before or soon after merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Reduce monitoring overhead in Cleanmeter" matches the main goal in the objectives and the changeset. The changes cut PresentMon row parsing cost, debug diagnostics, packet writes, forced GC…
Description check Passed The description lists the main changes: sidecar overhead reduction from PresentMon parsing, debug diagnostics, packet writes and forced GC; live sensor readings sent to Settings with snapshot replay; …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Reduce monitoring overhead in Cleanmeter" matches the main goal in the objectives and the changeset. The changes cut PresentMon row parsing cost, debug diagnostics, packet writes, forced GC, and display enumeration polling, all aimed at lower monitoring overhead. It is concise and specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description lists the main changes: sidecar overhead reduction from PresentMon parsing, debug diagnostics, packet writes and forced GC; live sensor readings sent to Settings with snapshot replay; and limited display enumeration. It also gives verification results and open test items, so it relates directly to the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Team
  • Run ID: e094f73e-d3c9-440b-adea-625323855fa3
Commits

Reviewing files that changed from the base of the PR and between 7f9662a and a571892.

Files selected for processing: 20

  • HardwareMonitor/HardwareMonitor.Tests/PercentileLowWiringTests.cs
  • HardwareMonitor/HardwareMonitor/HardwareMonitor.csproj
  • HardwareMonitor/HardwareMonitor/Monitor/MonitorPoller.cs
  • HardwareMonitor/HardwareMonitor/PresentMon/PresentMonPoller.cs
  • HardwareMonitor/HardwareMonitor/SharedMemory/SharedMemory.cs
  • tauri-app/src-tauri/src/commands.rs
  • tauri-app/src-tauri/src/lib.rs
  • tauri-app/src-tauri/src/pipe_client.rs
  • tauri-app/src-tauri/src/tray.rs
  • tauri-app/src/App.tsx
  • tauri-app/src/OverlayApp.tsx
  • tauri-app/src/components/overlay/FpsSection.tsx
  • tauri-app/src/hooks/useSensorData.ts
  • tauri-app/src/lib/gpu.ts
  • tauri-app/src/lib/overlay-displays.test.ts
  • tauri-app/src/lib/overlay-displays.ts
  • tauri-app/src/lib/tauri.ts
  • tauri-app/src/lib/utils.test.ts
  • tauri-app/src/lib/utils.ts
  • tauri-app/src/stores/settings-store.ts

Included review availability: This review used your included allowance. 7 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 8 reviews per hour.

stopBurst();
void refresh();
timer = setInterval(() => void refresh(), intervalMs);
endBurst = setTimeout(stopBurst, DISPLAY_POLL_BURST_MS);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Heavy lift

Monitor geometry can stay stale after a same-DPI resolution change.

Polling stops 60 seconds after each signal. After that, refresh runs only on resize, visibilitychange, or a DPI query change. A display resolution change at the same DPI can produce none of these events. The DPI query value does not change, visibilitychange does not fire, and resize fires only when the viewport size changes. The module subscribes to no display-change event.

The monitors state can then keep the previous x, y, width, and height. Later placement and clamping in OverlayApp.tsx can use these stale bounds and place the HUD against the wrong monitor area.

Monitor geometry must refresh after a display resolution change, including after the burst ends. Select a mechanism that the supported Windows and Tauri path delivers, and keep the burst behavior for startup retries.

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.

1 participant