Skip to content

⚡ Optimize startup CSS loading with parallel async I/O#7

Draft
google-labs-jules[bot] wants to merge 1 commit intomainfrom
perf-optimize-startup-io-16807734271977812758
Draft

⚡ Optimize startup CSS loading with parallel async I/O#7
google-labs-jules[bot] wants to merge 1 commit intomainfrom
perf-optimize-startup-io-16807734271977812758

Conversation

@google-labs-jules
Copy link

💡 What: Replaced the synchronous readFileSync loop for loading CSS files in source/index.ts with asynchronous fs.promises.readFile combined with Promise.all.

🎯 Why: The original implementation blocked the main thread during startup to read multiple CSS files from disk sequentially. This could cause UI freezes or delays in processing other events during the critical dom-ready phase.

📊 Implementation Details:

  • Imported readFile from node:fs/promises.
  • Created a filesToLoad array to handle the conditional workchat.css without mutating the original files constant.
  • Used Promise.all to read all CSS files concurrently.
  • Iterated over the resolved contents to call webContents.insertCSS in the correct order.
  • Removed await from insertCSS calls to treat them as fire-and-forget, avoiding IPC round-trip latency while preserving dispatch order (as synchronous dispatch ensures order in Electron).
  • Handled ENOENT errors gracefully, matching the original existsSync behavior but with a single syscall per file.

PR created automatically by Jules for task 16807734271977812758 started by @raztronaut

Replace synchronous `readFileSync` with `fs.promises.readFile` and `Promise.all` to read CSS files in parallel during application startup. This avoids blocking the main thread and allows the event loop to process other tasks, improving perceived startup performance and responsiveness.

The logic also ensures that:
- File reading happens in parallel.
- Order of CSS insertion is preserved by awaiting all reads and then inserting in order.
- IPC calls to `insertCSS` are non-blocking (fire-and-forget), maintaining low latency.
- Code hygiene is improved by not mutating the global file list.
@google-labs-jules
Copy link
Author

👋 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.

0 participants