From a85df575f7083562e598bd4ef006ea0e4eda4d4e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 5 May 2026 02:26:01 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Cache=20color=20map=20in=20?= =?UTF-8?q?StatusLine=20to=20prevent=20repeated=20allocations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement thread-safe caching of the ANSI color map at the StatusLine instance level. This prevents repeated map allocations and garbage collection overhead during concurrent plugin executions. Co-authored-by: himattm <6266621+himattm@users.noreply.github.com> --- .jules/bolt.md | 3 +++ internal/statusline/statusline.go | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..dfca091 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-05 - Cache instance-level static maps to prevent repeated allocations +**Learning:** Repeatedly creating static maps (like ANSI color maps) within concurrent operations (like plugin executions) causes unnecessary allocations and garbage collection overhead. +**Action:** Cache static data maps at the instance level (e.g., in the `StatusLine` struct) using `sync.Once` in a getter method to ensure thread-safety and maintain backward compatibility for tests. diff --git a/internal/statusline/statusline.go b/internal/statusline/statusline.go index ebbc115..2fde67d 100644 --- a/internal/statusline/statusline.go +++ b/internal/statusline/statusline.go @@ -35,6 +35,9 @@ type StatusLine struct { isIdle bool bashPlugins []plugin.Plugin // Cached discovered bash plugins bashPluginsOnce sync.Once + + colorsMap map[string]string + colorsMapOnce sync.Once } // New creates a new StatusLine renderer @@ -49,6 +52,13 @@ func New(input Input, cfg config.Config) *StatusLine { } // discoverBashPlugins discovers bash plugins once and caches them +func (sl *StatusLine) getColors() map[string]string { + sl.colorsMapOnce.Do(func() { + sl.colorsMap = colors.ColorMap() + }) + return sl.colorsMap +} + func (sl *StatusLine) discoverBashPlugins() []plugin.Plugin { sl.bashPluginsOnce.Do(func() { discovered, err := sl.pluginManager.Discover() @@ -634,7 +644,7 @@ func (sl *StatusLine) runPlugin(name string) string { ContextWindowSize: sl.input.Context.ContextWindow, }, Config: sl.getPluginConfig(name), - Colors: colors.ColorMap(), + Colors: sl.getColors(), } // Try native plugin first (much faster - no subprocess)