Skip to content

Conversation

@vLuckyyy
Copy link
Member

No description provided.

@vLuckyyy vLuckyyy requested a review from a team as a code owner January 11, 2026 22:32
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @vLuckyyy, 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 primarily focuses on performance optimizations and code refinement within the notice broadcasting system. Key changes include introducing caching for notice parts and translated formatters to reduce redundant computations, streamlining viewer collection logic, and improving exception handling practices. These updates aim to enhance the efficiency and robustness of how notices are processed and delivered.

Highlights

  • Notice Part Caching: The Notice class now caches its list of NoticePart objects, improving performance by avoiding repeated stream operations and list creation for frequently accessed parts.
  • Optimized Viewer Collection: The NoticeBroadcastImpl class has been refactored to directly add viewers to the collection, removing an unnecessary intermediate HashSet and simplifying the logic for viewer processing.
  • Translated Formatter Caching: A caching mechanism has been implemented for TranslatedFormatter instances in NoticeBroadcastImpl. This significantly reduces the overhead of creating new formatters and extracting placeholders for each language during notice broadcasting, leading to performance gains.
  • Refined Exception Handling: The NoticeResolverRegistry now catches Exception instead of Throwable, promoting better error handling practices by avoiding the capture of critical system errors that should typically propagate.

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

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 introduces caching for notice parts and translated formatters to improve performance, and refactors some viewer lookup logic. The caching for notice parts has a minor thread-safety issue. The caching for translated formatters has more significant issues: it uses a non-thread-safe HashMap in a concurrent context, and the cache invalidation logic (isDirty) is flawed, which could lead to stale data being used. I've provided detailed comments and suggestions to address these points.

});
}

private final Map<Locale, TranslatedFormatter> formatterCache = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The formatterCache is initialized as a HashMap, which is not thread-safe. Since send() can be executed asynchronously via sendAsync(), the prepareFormatterForLanguage method can be called by multiple threads concurrently. This can lead to race conditions when accessing formatterCache, potentially causing data corruption.

To ensure thread safety, you should use a thread-safe map implementation like java.util.concurrent.ConcurrentHashMap.

Suggested change
private final Map<Locale, TranslatedFormatter> formatterCache = new HashMap<>();
private final Map<Locale, TranslatedFormatter> formatterCache = new java.util.concurrent.ConcurrentHashMap<>();

Comment on lines +329 to 332
protected boolean isDirty() {
return NoticeBroadcastImpl.this.formatters.size() != expectedFormatterCount
|| NoticeBroadcastImpl.this.placeholders.size() != expectedPlaceholderCount;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The isDirty check is flawed because it only checks the size of the formatters and placeholders collections. This logic fails to detect modifications that don't change the collection size, such as replacing a placeholder with a new value for an existing key (e.g., calling placeholder("{key}", "new_value") after placeholder("{key}", "old_value") was already called). This can lead to stale formatters being served from the cache, resulting in incorrect messages.

A more robust approach would be to use a modification counter (e.g., an int or AtomicInteger field in NoticeBroadcastImpl) that is incremented every time formatters or placeholders are modified. The TranslatedFormatter would then store the modCount at creation time and compare it with the current modCount in isDirty().

Comment on lines +36 to +38
if (cachedParts == null) {
cachedParts = List.copyOf(this.parts.values());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The lazy initialization of cachedParts is not thread-safe. If multiple threads call parts() concurrently when cachedParts is null, they might all enter this if block, leading to redundant computation. While this is a benign race condition in this specific case, it's better to use a standard thread-safe lazy initialization pattern.

One option is to use double-checked locking, which would require making cachedParts volatile.

private volatile List<NoticePart<?>> cachedParts;
//...
public List<NoticePart<?>> parts() {
    if (cachedParts == null) {
        synchronized (this) {
            if (cachedParts == null) {
                cachedParts = List.copyOf(this.parts.values());
            }
        }
    }
    return cachedParts;
}

Alternatively, a simpler and safer approach would be to initialize cachedParts in the constructor and make it final, since the parts map is effectively immutable after construction.

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.

2 participants