Skip to content

Rustcast causes severe macOS mouse lag and WindowServer CPU spike #279

@cmolina

Description

@cmolina

Problem

After running Rustcast for several hours, macOS mouse responsiveness degrades significantly. The mouse becomes noticeably slow and unresponsive, with input events appearing to have 50-200ms delays. The issue is reproducible and occurs even if the laptop goes to sleep during the Rustcast session.

Root Cause Analysis

System Diagnostics (captured 2026-06-12 14:07:33):

WindowServer CPU Utilization

  • With Rustcast running: WindowServer at 38.0% CPU
  • After killing Rustcast: WindowServer dropped to 1.4% CPU (96.3% reduction ✓)

This is the critical finding: Rustcast is causing macOS's display compositing and input event processor (WindowServer) to become severely overloaded.

System State When Rustcast Active

  • Memory Used: 15 GB / 16 GB (93.75%)
  • Memory Compressor: 409,262 pages compressed
  • Physical Free Memory: 306 MB
  • System Uptime: 21 hours
  • Laptop: Had gone to sleep during Rustcast session

Memory Improvement Post-Fix

  • Pages in compressor: 409,262 → 182,726 (-55%)
  • Memory free %: 69% → 71%

Technical Details

The Problem

When Rustcast has been running for several hours, it causes macOS's WindowServer (the display compositing and input event processor) to spike to 38% CPU usage, creating a bottleneck that delays mouse input processing.

Why This Matters

  • macOS WindowServer is a single-threaded process that:
    • Receives input events (mouse, keyboard, trackpad)
    • Composites all windows/layers
    • Manages GPU command buffers
  • When Rustcast causes excessive rendering work, WindowServer CPU maxes out
  • Input events get queued behind rendering operations
  • Result: Laggy, unresponsive mouse

System Information

  • Device: MacBook Air (Mac14,2) with Apple M2
  • OS: macOS 26.3 (25D125)
  • RAM: 16 GB LPDDR5
  • Display: 2560 x 1664 Retina

Reproduction Steps

  1. Launch Rustcast
  2. Let it run for several hours (laptop may sleep during this time)
  3. Observe mouse responsiveness - should become sluggish
  4. Monitor Activity Monitor: Check WindowServer CPU usage (should be ~38%)
  5. Kill Rustcast: pkill -9 rustcast
  6. Observe: Mouse responsiveness returns to normal immediately, WindowServer CPU drops to <2%

Evidence

Before/After comparison:

WindowServer CPU: 38.0% → 1.4% ✓
Memory in Compressor: 409K pages → 182K pages ✓
System Idle CPU: 78.32% → 82.92% ✓

Recommended Investigation

  1. Check if Rustcast is creating excessive GPU draw calls
  2. Review rendering loop - may be redrawing more frequently than necessary
  3. Profile Metal GPU utilization with XCode Instruments
  4. Check if Rustcast is maintaining large memory buffers
  5. Verify GPU command buffer submission rates
  6. Test behavior after system sleep/wake cycles

Impact

  • Severity: High - Makes system unusable during extended Rustcast sessions
  • Frequency: Consistent and reproducible after several hours
  • Timing: Appears to accumulate over time, may worsen if laptop sleeps during session
  • Affected Users: Any macOS user running Rustcast for extended periods

Metadata

Metadata

Assignees

Labels

HIGH PRIORITYIssues that should be fixed ASAPassignedFor issues that have been assigned to someone to work onbefore v1.0.0Issue should be closed before v1.0.0bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions