From 46172ea28dbcafa660261f81606845c914d06616 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 30 Apr 2026 02:46:14 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Cache=20colors=20map=20in?= =?UTF-8?q?=20StatusLine=20to=20reduce=20allocations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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..e59eafe --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-04-30 - Map Allocation Overhead in Statusline Plugins +**Learning:** In performance-sensitive areas like concurrent plugin execution in the status line, calling functions like `colors.ColorMap()` repeatedly causes expensive map allocations per plugin execution, increasing memory usage and GC pressure. +**Action:** Cache static data maps at the instance level (e.g., in the `StatusLine` struct) during initialization to ensure thread-safety, minimize allocations, and improve plugin dispatch performance. diff --git a/internal/statusline/statusline.go b/internal/statusline/statusline.go index ebbc115..87b260b 100644 --- a/internal/statusline/statusline.go +++ b/internal/statusline/statusline.go @@ -35,6 +35,8 @@ type StatusLine struct { isIdle bool bashPlugins []plugin.Plugin // Cached discovered bash plugins bashPluginsOnce sync.Once + colorsMap map[string]string // Cached static colors map to avoid allocations + colorsMapOnce sync.Once } // New creates a new StatusLine renderer @@ -48,6 +50,14 @@ func New(input Input, cfg config.Config) *StatusLine { } } +// getColorsMap returns a cached colors map for plugin execution +func (sl *StatusLine) getColorsMap() map[string]string { + sl.colorsMapOnce.Do(func() { + sl.colorsMap = colors.ColorMap() + }) + return sl.colorsMap +} + // discoverBashPlugins discovers bash plugins once and caches them func (sl *StatusLine) discoverBashPlugins() []plugin.Plugin { sl.bashPluginsOnce.Do(func() { @@ -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.getColorsMap(), // Use cached instance-level map to avoid allocations per execution } // Try native plugin first (much faster - no subprocess)