-
Notifications
You must be signed in to change notification settings - Fork 1
⚡ Debounce continuous WindowSizePosLog.ini writes to drastically reduce Disk I/O #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,9 @@ ProcessSetPriority("Normal") | |||||||||||||||||||||
| MatchList := "" | ||||||||||||||||||||||
| ExclusionList := ["ShellExperienceHost.exe", "SearchUI.exe"] | ||||||||||||||||||||||
| LastSaved := Map() ; Cache for last saved positions to avoid redundant INI writes | ||||||||||||||||||||||
| LastSaved.CaseSense := "Off" | ||||||||||||||||||||||
| PendingWrites := Map() | ||||||||||||||||||||||
| PendingWrites.CaseSense := "Off" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ; Build initial list of windows | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
|
|
@@ -33,6 +36,7 @@ try { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| ; Main loop - monitor windows and save/restore positions | ||||||||||||||||||||||
| SetTimer(MonitorWindows, 350) | ||||||||||||||||||||||
| SetTimer(ProcessPendingWrites, 1000) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| MonitorWindows() { | ||||||||||||||||||||||
| global MatchList, ExclusionList, LastSaved | ||||||||||||||||||||||
|
|
@@ -76,7 +80,7 @@ MonitorWindows() { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| SaveCurrentWindowPosition() { | ||||||||||||||||||||||
| global ExclusionList, LastSaved | ||||||||||||||||||||||
| global ExclusionList, LastSaved, PendingWrites | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| WinGetPos(&X, &Y, &Width, &Height, "A") | ||||||||||||||||||||||
|
|
@@ -102,9 +106,27 @@ SaveCurrentWindowPosition() { | |||||||||||||||||||||
| ; Only write if position/size changed | ||||||||||||||||||||||
| currentValue := X . "," . Y . "," . Width . "," . Height | ||||||||||||||||||||||
| if (!LastSaved.Has(active_ProcessName) || LastSaved[active_ProcessName] != currentValue) { | ||||||||||||||||||||||
| IniWrite(currentValue, A_ScriptDir . "\WindowSizePosLog.ini", "Process Names", active_ProcessName) | ||||||||||||||||||||||
| LastSaved[active_ProcessName] := currentValue | ||||||||||||||||||||||
| PendingWrites[active_ProcessName] := A_TickCount | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ProcessPendingWrites() { | ||||||||||||||||||||||
| global PendingWrites, LastSaved | ||||||||||||||||||||||
| currentTime := A_TickCount | ||||||||||||||||||||||
| keysToDelete := [] | ||||||||||||||||||||||
| for processName, lastChangeTime in PendingWrites { | ||||||||||||||||||||||
| if (currentTime - lastChangeTime >= 1000) { | ||||||||||||||||||||||
| if (LastSaved.Has(processName)) { | ||||||||||||||||||||||
| currentValue := LastSaved[processName] | ||||||||||||||||||||||
| IniWrite(currentValue, A_ScriptDir . "\WindowSizePosLog.ini", "Process Names", processName) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| keysToDelete.Push(processName) | ||||||||||||||||||||||
|
Comment on lines
+124
to
+126
|
||||||||||||||||||||||
| IniWrite(currentValue, A_ScriptDir . "\WindowSizePosLog.ini", "Process Names", processName) | |
| } | |
| keysToDelete.Push(processName) | |
| try { | |
| IniWrite(currentValue, A_ScriptDir . "\WindowSizePosLog.ini", "Process Names", processName) | |
| keysToDelete.Push(processName) | |
| } catch e { | |
| OutputDebug("WM.ahk: Failed to write INI for process '" . processName . "': " . e.Message) | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The debounce behavior here can exceed the stated 1000ms: the timer runs every 1000ms and you also require
>= 1000elapsed, so the actual write can happen ~1000–2000ms after the last change depending on timer alignment. If the intent is “write 1000ms after inactivity”, consider using a shorter polling interval (e.g., 250ms) or switching to a one-shot timer that gets reset on each change (e.g., scheduleProcessPendingWriteswith a negative period on updates).