β‘ Unblock event loop by using async file I/O in IPC handlers#3
Conversation
Converts synchronous file reads (`fs.readFileSync`) and access checks (`fs.accessSync`) in the `IpcMessages.REQUEST_PLATFORMS_AVAILABLE` handler to their asynchronous Promise-based equivalents. This prevents blocking the Node.js event loop in the Electron main process, improving application responsiveness, particularly when checking for available games on custom platforms or Linux environments. Co-authored-by: Er1ckW <[email protected]>
|
π 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
β‘ Performance Improvement
π‘ What:
Refactored the callback for
ipcMain.handle(IpcMessages.REQUEST_PLATFORMS_AVAILABLE, ...)to useasync/await. Replaced synchronous file I/O methods:fs.readFileSync(used to check the Linux Steam registry file) was replaced withawait fs.promises.readFile.fs.accessSync(used to check for the existence of custom platform executables) was replaced withawait fs.promises.access.π― Why:
Synchronous operations in Electron's main process block the event loop, causing the application UI to hang or become unresponsive. When loading multiple game platforms or reading large files, these blocking reads add perceptible delays. Converting them to asynchronous operations allows the event loop to continue processing other IPC messages and UI updates while waiting for the filesystem.
π Measured Improvement:
Before implementing this change, a focused benchmark was created to measure event loop lag caused by repeated synchronous reads.
Benchmark Setup:
Measuring event loop lag while attempting to sequentially read files, mimicking the iteration over custom platforms in the handler.
By migrating to
fs.promises, the event loop lag for these operations is effectively eliminated, representing a significant unblocking of the main thread.PR created automatically by Jules for task 7114442595535708730 started by @Er1ckW