Skip to content

⚡ Bolt: Cache ColorMap to prevent repeated map allocations#78

Closed
himattm wants to merge 1 commit intomainfrom
bolt/cache-colormap-15580878599962567874
Closed

⚡ Bolt: Cache ColorMap to prevent repeated map allocations#78
himattm wants to merge 1 commit intomainfrom
bolt/cache-colormap-15580878599962567874

Conversation

@himattm
Copy link
Copy Markdown
Owner

@himattm himattm commented May 1, 2026

💡 What: Caches the return value of colors.ColorMap() at the StatusLine instance level rather than repeatedly invoking it on every plugin execution.
🎯 Why: runPlugin() is invoked in parallel goroutines. Repeatedly allocating a large 100+ item map causes unnecessary memory allocation and garbage collection pressure in a performance-critical path.
📊 Impact: Reduces heap allocations during status line rendering by one map allocation per configured section, speeding up rendering by reducing GC pressure.
🔬 Measurement: Run benchmark rendering, observe reduced allocs/op using Go benchmarks. Tested explicitly with the race detector (go test -race ./...) to ensure thread-safe caching.


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

In performance-sensitive areas with highly concurrent paths (e.g. statusline rendering with plugins executed in parallel), repeatedly allocating new large maps (like a color lookup map via colors.ColorMap()) causes measurable allocation overhead and garbage collection pressure.

This commit caches the static color data map at the instance level in the StatusLine struct. Using sync.Once for lazy initialization ensures thread-safety without regressions for test suites.

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 implements caching for the color map within the StatusLine struct to improve performance by reducing repeated allocations during statusline rendering. It introduces a getColorMap method that utilizes sync.Once for thread-safe lazy initialization. The review feedback suggests removing the redundant initialization of the color map in the New constructor to simplify the code and ensure consistent use of the lazy-loading getter.

pluginManager: plugin.NewManager(),
nativePlugins: plugins.NewRegistry(),
isIdle: checkIsIdle(input.SessionID),
colorMap: colors.ColorMap(),
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

The initialization of colorMap in the New constructor is redundant because getColorMap handles lazy initialization via sync.Once. Removing this call simplifies the constructor and ensures consistent initialization through the getter.

Suggested change
colorMap: colors.ColorMap(),
colorMap: nil,

@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-colormap-15580878599962567874 branch May 7, 2026 15:35
@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 the 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