From a0d66fa5cd59ee9f4096c38f038ebce779b20c2d Mon Sep 17 00:00:00 2001 From: yuchou87 Date: Sat, 21 Feb 2026 13:48:41 +0800 Subject: [PATCH] perf(agent): cache ListAgentIDs() result before MCP tool registration loop ListAgentIDs() was called on every iteration of the inner tool loop, causing repeated allocations. Capture the slice once and reuse it for both agentCount and the registration loop. --- pkg/agent/loop.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index e3efea17b..eef800921 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -185,12 +185,13 @@ func (al *AgentLoop) Run(ctx context.Context) error { servers := mcpManager.GetServers() uniqueTools := 0 totalRegistrations := 0 - agentCount := len(al.registry.ListAgentIDs()) + agentIDs := al.registry.ListAgentIDs() + agentCount := len(agentIDs) for serverName, conn := range servers { uniqueTools += len(conn.Tools) for _, tool := range conn.Tools { - for _, agentID := range al.registry.ListAgentIDs() { + for _, agentID := range agentIDs { agent, ok := al.registry.GetAgent(agentID) if !ok { continue