Skip to content

Commit 0c70189

Browse files
vojtabiberleclaude
andcommitted
DMD-921 - Optimize most-connected-nodes to use slice limit
Slice the nodes array to 20 elements before iterating, rather than checking the index in each iteration. Also preallocate the output slice capacity. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5ae06f2 commit 0c70189

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

internal/pkg/llm/twinformat/generator.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,12 +1072,14 @@ func (g *Generator) generateMostConnectedNodes(ctx context.Context, data *Proces
10721072
return nodes[i].Connections > nodes[j].Connections
10731073
})
10741074

1075-
// Take top 20.
1076-
topNodes := make([]map[string]any, 0)
1077-
for i, node := range nodes {
1078-
if i >= 20 {
1079-
break
1080-
}
1075+
// Limit to top 20 nodes.
1076+
if len(nodes) > 20 {
1077+
nodes = nodes[:20]
1078+
}
1079+
1080+
// Convert to output format.
1081+
topNodes := make([]map[string]any, 0, len(nodes))
1082+
for _, node := range nodes {
10811083
topNodes = append(topNodes, map[string]any{
10821084
"uid": node.UID,
10831085
"connections": node.Connections,

0 commit comments

Comments
 (0)