Skip to content

⚡ Bolt: Cache colors map to reduce allocations#84

Closed
himattm wants to merge 1 commit intomainfrom
bolt-cache-colors-map-9519186400810483619
Closed

⚡ Bolt: Cache colors map to reduce allocations#84
himattm wants to merge 1 commit intomainfrom
bolt-cache-colors-map-9519186400810483619

Conversation

@himattm
Copy link
Copy Markdown
Owner

@himattm himattm commented May 4, 2026

💡 What: Caches the output of colors.ColorMap() within the StatusLine struct using sync.Once.
🎯 Why: The StatusLine previously called colors.ColorMap() every time runPlugin was executed. colors.ColorMap() allocates and returns a new map with 30+ string key-value pairs each time it's called. Since plugins are executed repeatedly (and concurrently), this caused significant, unnecessary garbage collection overhead and map allocation. Caching it eliminates this overhead.
📊 Impact: Reduces memory allocations per plugin execution, resulting in lower GC pressure and slightly improved performance, especially when many plugins are running or the prompt is rendered frequently.
🔬 Measurement: This optimization improves runtime performance by avoiding repeated heap allocations for the map. Tests pass successfully in ~0.9s.


PR created automatically by Jules for task 9519186400810483619 started by @himattm

Co-authored-by: himattm <6266621+himattm@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.

Copy link
Copy Markdown

@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 a caching mechanism for the color map within the StatusLine struct to optimize performance by reducing allocations during plugin execution. The implementation uses sync.Once for thread-safe, lazy initialization. A review comment points out a potential thread-safety risk if plugins modify the shared map and suggests adding documentation to ensure the map is treated as read-only.

Comment on lines +42 to +43
// getColorsMap returns the cached colors map, initializing it safely if needed.
func (sl *StatusLine) getColorsMap() map[string]string {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Caching the color map and sharing it across multiple plugin executions introduces a potential thread-safety issue. Since Go maps are reference types and are not thread-safe for concurrent access if any writer is involved, a native plugin that modifies the Colors map in its Input struct could cause a data race or unexpected side effects for other plugins running concurrently. It is recommended to document that the returned map must be treated as read-only by all consumers.

// getColorsMap returns the cached colors map, initializing it safely if needed.
// The returned map is shared across plugins and must be treated as read-only.
func (sl *StatusLine) getColorsMap() map[string]string {

@himattm
Copy link
Copy Markdown
Owner Author

himattm commented May 7, 2026

Closing as superseded by direct commit 42f3149 on main, which consolidated the StatusLine color-map caching optimization without the generated .jules note.

@himattm himattm closed this May 7, 2026
@himattm himattm deleted the bolt-cache-colors-map-9519186400810483619 branch May 7, 2026 15:34
@google-labs-jules
Copy link
Copy Markdown
Contributor

Closing as superseded by direct commit 42f3149 on main, which consolidated the StatusLine color-map caching optimization without the generated .jules note.

Understood. Acknowledging that this work is now superseded by a direct commit on main and stopping work on 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.

1 participant