Skip to content

perf(cli): cache loadSettings to reduce redundant disk I/O at startup#21521

Merged
scidomino merged 5 commits intomainfrom
perf/cache-load-settings
Mar 9, 2026
Merged

perf(cli): cache loadSettings to reduce redundant disk I/O at startup#21521
scidomino merged 5 commits intomainfrom
perf/cache-load-settings

Conversation

@sehoon38
Copy link
Copy Markdown
Contributor

@sehoon38 sehoon38 commented Mar 7, 2026

Summary

This PR caches the results of loadSettings to reduce redundant disk I/O and configuration merging overhead during CLI startup and initialization.

Details

  • Implemented an in-memory cache with a 30-second TTL for loadSettings in packages/cli/src/config/settings.ts using the core createCache utility. This covers the burst of reads that happen natively when launching the CLI or executing a sub-process.
  • saveSettings now clears the cache to ensure that changes take effect immediately.
  • Added resetSettingsCacheForTesting() for test isolation.
  • Added robust unit testing for the cache hit rates and clearing logic in packages/cli/src/config/settings.test.ts.

Related Issues

Fixes #17988

How to Validate

  1. Run the test suite:
    npm test -w @google/gemini-cli -- src/config/settings.test.ts
  2. Start the CLI normally and ensure there's no functionality degradation.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@sehoon38 sehoon38 requested a review from a team as a code owner March 7, 2026 04:11
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Mar 7, 2026

Hi @sehoon38, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

Thank you for your understanding and for being a part of our community!

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the performance of the CLI by introducing a caching layer for configuration loading. The primary goal is to minimize repetitive disk I/O operations and reduce the computational overhead associated with merging various configuration settings, thereby leading to a faster and more efficient startup experience for the command-line interface.

Highlights

  • Performance Improvement: Implemented an in-memory cache for loadSettings with a 5-second TTL to significantly reduce redundant disk I/O and configuration merging overhead during CLI startup.
  • Cache Management: Modified saveSettings to automatically clear the loadSettings cache, ensuring that any configuration changes are immediately reflected in subsequent loads.
  • Testability and Validation: Introduced a dedicated resetSettingsCacheForTesting() function for improved test isolation and added comprehensive unit tests to validate the new caching logic and its behavior.
Changelog
  • packages/cli/src/config/settings.test.ts
    • Imported the new resetSettingsCacheForTesting utility.
    • Added a call to resetSettingsCacheForTesting() in the beforeEach hook to ensure test isolation.
    • Introduced a new test suite specifically for the caching mechanism, covering scenarios like cache hits, separate caches for different workspaces, and cache invalidation upon saving settings.
  • packages/cli/src/config/settings.ts
    • Imported the createCache utility from @google/gemini-cli-core.
    • Defined and initialized settingsCache as an in-memory cache with a 5-second Time-To-Live (TTL).
    • Exported resetSettingsCacheForTesting() to allow clearing the cache, primarily for testing purposes.
    • Refactored loadSettings to utilize the settingsCache, retrieving existing settings or delegating to a new internal function for initial loading.
    • Renamed the original implementation of loadSettings to _doLoadSettings and made it a private function.
    • Added a call to settingsCache.clear() within saveSettings to ensure the cache is invalidated when settings are modified and saved.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an in-memory cache for loadSettings to improve startup performance by reducing disk I/O. The implementation correctly uses a cache with a 5-second TTL and invalidates it when settings are saved. The associated tests are well-written and cover the new caching logic. I have one suggestion to make the cache invalidation more granular for an even greater performance benefit, aligning with our caching guidelines.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 7, 2026

Size Change: +336 B (0%)

Total Size: 26 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.6 MB +336 B (0%)
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@gemini-cli gemini-cli bot added area/core Issues related to User Interface, OS Support, Core Functionality area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Mar 7, 2026
@sehoon38 sehoon38 force-pushed the perf/cache-load-settings branch from 641c20a to dcb2389 Compare March 7, 2026 04:59
@sehoon38 sehoon38 force-pushed the perf/cache-load-settings branch from dcb2389 to d711107 Compare March 7, 2026 05:28
Copy link
Copy Markdown
Collaborator

@scidomino scidomino left a comment

Choose a reason for hiding this comment

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

I'm worried that caching is not the right way to do this. There are a lot of processes that load the settings after modifying them and this would make it break if you try to do that twice within 30 seconds (like uninstalling and reinstalling an extension).

scidomino

This comment was marked as outdated.

scidomino

This comment was marked as outdated.

}

export function saveSettings(settingsFile: SettingsFile): void {
if (settingsFile.path === USER_SETTINGS_PATH) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To keep things simple, we should just invalidate the entire cache every time. The extra complexity is not worth it.

@sehoon38 sehoon38 added this pull request to the merge queue Mar 9, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 9, 2026
@scidomino scidomino added this pull request to the merge queue Mar 9, 2026
Merged via the queue into main with commit 1fd4280 Mar 9, 2026
27 checks passed
@scidomino scidomino deleted the perf/cache-load-settings branch March 9, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate on loadSettings being called 3 times

2 participants