Skip to content

⚡ Debounce continuous WindowSizePosLog.ini writes to drastically reduce Disk I/O#45

Merged
Ven0m0 merged 1 commit intomainfrom
perf-debounce-ini-writes-1848832163621820363
Mar 1, 2026
Merged

⚡ Debounce continuous WindowSizePosLog.ini writes to drastically reduce Disk I/O#45
Ven0m0 merged 1 commit intomainfrom
perf-debounce-ini-writes-1848832163621820363

Conversation

@Ven0m0
Copy link
Owner

@Ven0m0 Ven0m0 commented Mar 1, 2026

💡 What:
The optimization changes the IniWrite operation that previously occurred on every window drag/resize loop execution into a deferred, debounced disk write operation.

🎯 Why:
The performance problem is excessive disk I/O when tracking window positions. The MonitorWindows loop runs every 350ms. When dragging a window, a single IniWrite was called on each loop iteration, leading to hundreds of unnecessary synchronous writes. The final resting position is all that needs to be logged.

📊 Measured Improvement:
Dynamic execution of AHK benchmark was not performed since the environment lacks Wine (autohotkey command is missing). However, mathematically, a 10-second continuous window drag operation that previously caused ~28 individual disk I/O write operations (1 per 350ms) now performs exactly 0 disk writes during dragging and 1 disk write after 1000ms of inactivity, resulting in near 100% reduction of blocking operations over that timespan.


PR created automatically by Jules for task 1848832163621820363 started by @Ven0m0

* Implemented a `PendingWrites` map with disabled CaseSense.
* Initialized a 1000ms `SetTimer` to run `ProcessPendingWrites`.
* Modified `SaveCurrentWindowPosition` to defer IniWrite calls to memory instead of writing directly to disk, dramatically reducing I/O usage during drag/resize events.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 1, 2026 06:34
@gemini-code-assist
Copy link

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces disk I/O in the Window Manager GUI script by deferring IniWrite calls while a window is actively moving/resizing, then writing the final position after inactivity.

Changes:

  • Introduces LastSaved/PendingWrites maps (case-insensitive) to track last position and pending debounced writes.
  • Adds a ProcessPendingWrites timer to flush queued INI updates after an inactivity threshold.
  • Updates SaveCurrentWindowPosition() to queue writes instead of writing immediately.

Comment on lines +124 to +126
IniWrite(currentValue, A_ScriptDir . "\WindowSizePosLog.ini", "Process Names", processName)
}
keysToDelete.Push(processName)
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProcessPendingWrites() calls IniWrite() without any error handling. If the INI write fails (file locked, permission issues, etc.), the timer thread can throw and potentially stop processing future pending writes. Consider wrapping the write in a try and only removing the entry from PendingWrites after a successful write (or keeping it queued to retry).

Suggested change
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)
}
}

Copilot uses AI. Check for mistakes.

; Main loop - monitor windows and save/restore positions
SetTimer(MonitorWindows, 350)
SetTimer(ProcessPendingWrites, 1000)
Copy link

Copilot AI Mar 1, 2026

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 >= 1000 elapsed, 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., schedule ProcessPendingWrites with a negative period on updates).

Copilot uses AI. Check for mistakes.
@Ven0m0 Ven0m0 merged commit 080fb07 into main Mar 1, 2026
7 of 8 checks passed
@Ven0m0 Ven0m0 deleted the perf-debounce-ini-writes-1848832163621820363 branch March 1, 2026 07:44
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.

2 participants