Skip to content

⚡ [optimize saveConfig to use asynchronous I/O]#106

Open
cmuench wants to merge 2 commits into
mainfrom
perf-async-config-save-7143591505039929346
Open

⚡ [optimize saveConfig to use asynchronous I/O]#106
cmuench wants to merge 2 commits into
mainfrom
perf-async-config-save-7143591505039929346

Conversation

@cmuench
Copy link
Copy Markdown
Contributor

@cmuench cmuench commented May 8, 2026

⚡ Performance Optimization: Asynchronous Configuration Saving

💡 What:

Replaced synchronous file system operations in lib/config.js with their asynchronous counterparts using the fs.promises API. This affects configuration loading/saving, token cache management, and old configuration migration.

🎯 Why:

The saveConfig and related functions were already marked as async, yet they utilized blocking synchronous calls (e.g., fs.writeFileSync, fs.readFileSync). This blocks the Node.js event loop during I/O operations. Transitioning to fs.promises ensures that the CLI remains responsive and follows Node.js best practices for non-blocking I/O.

📊 Measured Improvement:

While sequential benchmarks for small file writes (e.g., 100 calls to saveConfig) showed a slight overhead (~98ms baseline vs ~110-120ms optimized), the primary benefit is the elimination of event loop blocking. This is particularly important for maintaining responsiveness in a CLI environment that handles multiple asynchronous tasks.

✅ Verification:

  • All 623 tests in the suite passed, including specialized tests for configuration management and security (file permissions).
  • tests/config.test.js was updated to mock fs.promises and verify that the correct asynchronous methods are invoked with appropriate parameters.
  • Security protocols for file permissions (0o600 for files, 0o700 for directories) were preserved and verified through tests/security.test.js.

PR created automatically by Jules for task 7143591505039929346 started by @cmuench

- Replace synchronous `fs` methods with `fs.promises` in `lib/config.js`.
- Refactor `saveConfig`, `loadConfig`, `saveTokenCache`, `loadTokenCache`, `clearTokenCache`, and `migrateOldConfig` to be fully asynchronous.
- Ensure secure file permissions (0o600) and directory permissions (0o700) are maintained using `fs.promises.chmod` and `mkdirp` modes.
- Update `tests/config.test.js` to support and verify asynchronous file operations.
- Improve event loop responsiveness by avoiding blocking I/O in the CLI's async flows.

Co-authored-by: cmuench <211294+cmuench@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
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.

@cmuench
Copy link
Copy Markdown
Contributor Author

cmuench commented May 17, 2026

@jules resolve conflicts

@google-labs-jules
Copy link
Copy Markdown
Contributor

@jules resolve conflicts

I have verified that the current branch is up to date with origin/main and there are no conflicts. I'll proceed with submitting the changes.

- Replace synchronous `fs` methods with `fs.promises` in `lib/config.js`.
- Refactor `saveConfig`, `loadConfig`, `saveTokenCache`, `loadTokenCache`, `clearTokenCache`, and `migrateOldConfig` to be fully asynchronous.
- Ensure secure file permissions (0o600) and directory permissions (0o700) are maintained using `fs.promises.chmod` and `mkdirp` modes.
- Update `tests/config.test.js` to support and verify asynchronous file operations.
- Verified branch is up to date with origin/main.

Co-authored-by: cmuench <211294+cmuench@users.noreply.github.com>
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