Skip to content

perf(watcher): reduce auth cache memory#2126

Open
ailuntz wants to merge 1 commit intorouter-for-me:mainfrom
ailuntz:fix/watcher-auth-cache-memory
Open

perf(watcher): reduce auth cache memory#2126
ailuntz wants to merge 1 commit intorouter-for-me:mainfrom
ailuntz:fix/watcher-auth-cache-memory

Conversation

@ailuntz
Copy link

@ailuntz ailuntz commented Mar 14, 2026

Summary

  • Reduce watcher auth cache memory usage.

Testing

  • Not run (not requested).

@gemini-code-assist
Copy link
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 significantly improves the memory performance of the watcher component by strategically reducing the size of its authentication caches. It achieves this by only storing detailed authentication content when debug logging is active and by converting a map of authentication objects into a more memory-efficient set of authentication IDs.

Highlights

  • Memory Optimization: Optimized memory usage by making the caching of lastAuthContents conditional on the debug logging level, reducing the memory footprint when debug logging is not enabled.
  • Data Structure Efficiency: Reduced the memory footprint of fileAuthsByPath by storing only authentication IDs (keys) instead of full coreauth.Auth objects, effectively turning it into a set of IDs.
  • New Helper Function: Introduced a new helper function authIDSet to create a map of authentication IDs from an existing map of authentication objects.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • internal/watcher/clients.go
    • w.lastAuthContents initialization and population were made conditional on the debug logging level.
    • w.fileAuthsByPath now stores only authentication IDs using the new authIDSet helper.
    • A new authIDSet function was added to create a map of authentication IDs.
Activity
  • Testing was not run as it was not requested.
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
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 effectively reduces memory usage in the watcher by making the auth content cache conditional on the debug log level and by optimizing the storage of auth file paths to only store IDs instead of full auth objects. These are great performance improvements. I have one suggestion to further optimize memory usage in the new authIDSet function.

Comment on lines +288 to +293
func authIDSet(auths map[string]*coreauth.Auth) map[string]*coreauth.Auth {
set := make(map[string]*coreauth.Auth, len(auths))
for id := range auths {
set[id] = nil
}
return set
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This is a good memory optimization. For even better memory efficiency, consider using map[string]struct{}. An empty struct{} is zero-width, while a nil pointer still has a size (e.g., 8 bytes on 64-bit machines).

This would require changing the type of w.fileAuthsByPath to map[string]map[string]struct{} and updating this function to return map[string]struct{}. The call sites would also need to be adjusted.

Copy link
Collaborator

@luispater luispater left a comment

Choose a reason for hiding this comment

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

Summary:
I did not find any blocking correctness issues in this change. The new ID-only fileAuthsByPath cache is still sufficient for add/delete detection, and full auth-content caching is now correctly limited to debug logging scenarios.

Key findings:

  • Blocking: none.
  • Non-blocking: there is no targeted regression test for the non-debug path where lastAuthContents stays nil and fileAuthsByPath stores ID-only entries. Existing watcher tests give indirect coverage, but a focused test would make this optimization safer to maintain.

Test plan:

  • go test ./...

Checks considered:

  • build: passed
  • translator-path-guard: intentionally ignored per review instructions

This is an automated Codex review result and still requires manual verification by a human reviewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants