Skip to content

Conversation

@frankdierolf
Copy link
Owner

@frankdierolf frankdierolf commented Jan 20, 2026

Summary

Fixes #23 - CPU usage while idle due to 10ms polling loop.

  • Replace 10ms polling loop with tokio::select! for event-driven operation
  • Convert hotkey channel from std::sync::mpsc to tokio::sync::mpsc
  • Make IPC server async by accepting connections in a background thread
  • Service now has zero CPU usage when idle (was ~100 wakeups/sec)

Technical Details

The service loop previously used non-blocking calls with a 10ms sleep:

loop {
    if let Some(conn) = ipc_server.try_accept()? { ... }
    if let Ok(event) = rx.try_recv() { ... }
    sleep(Duration::from_millis(10)).await;
}

Now uses tokio::select! to block until there's actual work:

loop {
    tokio::select! {
        Some(conn) = ipc_server.accept() => { ... }
        Some(event) = hotkey_rx.recv() => { ... }
    }
}

Test plan

  • Run whis start and verify it starts normally
  • Check CPU usage with top or htop - should be ~0% when idle
  • Test whis toggle command works via IPC
  • Test direct hotkey mode works (if configured)
  • Test push-to-talk mode works (if configured)

The service loop previously polled IPC and hotkey at 100 Hz (10ms sleep),
causing unnecessary CPU usage even when idle.

Changes:
- Convert hotkey channel from std::sync::mpsc to tokio::sync::mpsc
- Make IPC server async by accepting connections in background thread
- Replace polling loop with tokio::select! for zero-CPU idle state

Fixes #23
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.

whis-cli 0.7.2 : start uses CPU while idle (10ms polling loop on IPC + hotkey)

2 participants