Skip to content

⚑ perf: eliminate synchronous fs operations from main process#18

Open
BTawaifi wants to merge 1 commit intomainfrom
fix/sync-fs-operations-2206995012221350477
Open

⚑ perf: eliminate synchronous fs operations from main process#18
BTawaifi wants to merge 1 commit intomainfrom
fix/sync-fs-operations-2206995012221350477

Conversation

@BTawaifi
Copy link
Owner

@BTawaifi BTawaifi commented Mar 3, 2026

πŸ’‘ What: Eliminated all usages of synchronous fs.existsSync in the Electron main process, replacing them with asynchronous error-checking approaches (e.g., catching ENOENT during fs.readFile and fs.mkdir).

🎯 Why: The Node.js event loop in the Electron main process handles inter-process communication (IPC) and application lifecycle management. Synchronous I/O operations stall this thread, directly degrading the performance, responsiveness, and smoothness of the application for the end user. This fix aligns the I/O operations with the asynchronous paradigm.

πŸ“Š Measured Improvement:
Benchmarking 50,000 read operations locally demonstrated significant reductions in max event loop delay and total execution time:

  • Baseline (fs.existsSync + readFile): Total time ~15,100 ms | Max Event Loop Block: 4,418.50 ms | Operations/sec: ~3,311
  • Optimized (readFile with ENOENT catch): Total time ~7,191 ms | Max Event Loop Block: 2,246.12 ms | Operations/sec: ~6,952

The optimization resulted in over a 50% decrease in total time taken and almost halved the maximum event loop block delay under heavy load.


PR created automatically by Jules for task 2206995012221350477 started by @BTawaifi

Replaced all blocking `fs.existsSync` calls in `electron/main.js` with asynchronous equivalents using `fs.promises` (such as `readFile` error checking and `access`).

Benchmark Results (Max Event Loop Block on 50k iterations):
- `Sync existsSync`: 4418.50 ms
- `Async readFile`: 2246.12 ms

This prevents UI and application stuttering during I/O operations by halving the maximum event loop block duration under heavy load.

Co-authored-by: BTawaifi <52285931+BTawaifi@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.

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.

1 participant