Skip to content

feat/fix: Enhance stability and optimize performance for MSI Afterburner monitoring#5

Open
R0bles wants to merge 1 commit into
ethanperrine:mainfrom
R0bles:main
Open

feat/fix: Enhance stability and optimize performance for MSI Afterburner monitoring#5
R0bles wants to merge 1 commit into
ethanperrine:mainfrom
R0bles:main

Conversation

@R0bles
Copy link
Copy Markdown

@R0bles R0bles commented May 1, 2026

📝 Description

This PR introduces a series of critical stability fixes to prevent silent application crashes and implements several performance optimizations to reduce the system footprint. The main goal was to resolve OS-level Access Violations and improve the efficiency of the event-driven monitoring system.

🛠️ Technical Changes

Stability & Robustness

  • Fixed Hard Crashes: Replaced dynamic syscall.NewCallback creation with a static global callback (enumCallback) in watcher/watcher.go to prevent memory instability and Access Violations.
  • Panic Recovery: Added defer recover() blocks within Windows API callbacks to ensure that any internal panic is logged without terminating the entire process.
  • Process Persistence: Implemented an "Idle Mode" in main.go, allowing the script to remain active even when MSI Afterburner is not running.

Performance & Resource Optimization

  • Worker Pattern: Decoupled OS callbacks from processing logic using a channel-based worker pattern, improving responsiveness and stability.
  • Throttling: Added event_throttle_ms to config.json and config/config.go to prevent CPU spikes during rapid window state changes. Testing showed that values between 200ms and 400ms are optimal for maintaining responsiveness without missing events; therefore, a default of 200ms was implemented.
  • I/O Optimization: Implemented configuration caching to eliminate redundant disk reads during the main loop execution.

Debug

  • Log Filtering: Reduced log spam by implementing a state-aware notification system for Afterburner detection.

🧪 How to Test

  1. Stability Test: Run the application and open/close MSI Afterburner multiple times. The script should remain active (Idle Mode) and not crash.
  2. Performance Test: Trigger rapid window changes (e.g., Alt-Tab frequently or open Task Manager). Prior to this fix, these actions caused severe CPU spikes with events triggering every ~30ms—an unacceptable overhead for a lightweight background utility. Monitor CPU usage to verify that event_throttle_ms now effectively limits these spikes.
  3. Log Verification: Check the console output; "MSI Afterburner not detected" should only appear once per absence period.

✅ Checklist

  • Fixed silent crashes (Access Violations).
  • Implemented process persistence (Idle Mode).
  • Reduced CPU and Disk I/O overhead.

🔗 Related Issue

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.

Fix: Improve Application Stability and Performance (Hard Crash Prevention & Resource Optimization)

1 participant