📝 Overview
This issue summarizes the critical stability fixes and performance optimizations implemented to prevent silent crashes, reduce resource consumption, and improve the overall robustness of the MSI Afterburner monitoring script.
All changes were implemented while respecting the original author's design philosophy, ensuring that only the minimum necessary modifications were made to achieve stability and efficiency.
🔴 Problems Identified
During the diagnostic phase, several critical issues were identified:
- Silent Hard Crashes: The application experienced abrupt terminations (Access Violations) when interacting with the Windows API (
user32.dll), which bypassed Go's standard panic recovery.
- Process Termination: The script would exit automatically whenever the MSI Afterburner process was not detected, requiring manual restarts.
- CPU Spikes: Rapid window changes caused bursts of activity that led to significant CPU spikes.
- High Disk I/O & Runtime Instability: Repeatedly reloading configuration files from disk during Event and Polling modes created unnecessary overhead. Furthermore, modifying
config.json while the application was running (especially in event mode) triggered rapid reloads every few milliseconds, leading to critical application crashes.
🟢 Solutions Implemented
1. Stability & Crash Prevention
- Static Callbacks: Refactored the
watcher to use a static global callback instead of creating dynamic callbacks via syscall.NewCallback in loops, eliminating memory instability and Access Violations.
- System Thread Recovery: Integrated
defer recover() blocks directly within Windows API callbacks to capture panics at the OS level before they could crash the process.
- Idle Mode: Modified the main execution loop to enter an "idle" state when Afterburner is closed, ensuring the script remains active in the background.
2. Performance Optimizations
- Worker Pattern: Implemented a decoupled worker pattern for event-driven monitoring using channels and dedicated goroutines.
- Execution Throttling: Introduced
event_throttle_ms in config.json to limit processing frequency during rapid events.
- Config Caching: Eliminated redundant disk reads by utilizing a cached version of the configuration loaded at startup. Runtime reloading has been disabled to ensure stability; any changes to
config.json now require a process restart to take effect.
3. Logging
- State-Aware Detection: Implemented a system that only logs the absence of MSI Afterburner once per period, reducing log noise.
🚀 Impact
📝 Overview
This issue summarizes the critical stability fixes and performance optimizations implemented to prevent silent crashes, reduce resource consumption, and improve the overall robustness of the MSI Afterburner monitoring script.
All changes were implemented while respecting the original author's design philosophy, ensuring that only the minimum necessary modifications were made to achieve stability and efficiency.
🔴 Problems Identified
During the diagnostic phase, several critical issues were identified:
user32.dll), which bypassed Go's standard panic recovery.config.jsonwhile the application was running (especially in event mode) triggered rapid reloads every few milliseconds, leading to critical application crashes.🟢 Solutions Implemented
1. Stability & Crash Prevention
watcherto use a static global callback instead of creating dynamic callbacks viasyscall.NewCallbackin loops, eliminating memory instability and Access Violations.defer recover()blocks directly within Windows API callbacks to capture panics at the OS level before they could crash the process.2. Performance Optimizations
event_throttle_msinconfig.jsonto limit processing frequency during rapid events.config.jsonnow require a process restart to take effect.3. Logging
🚀 Impact