Skip to content

Commit f7ce96c

Browse files
committed
perf(gateway): add map capacity preallocation hints
- Add capacity hint to aiServices map in admin/server_ai.go - Add capacity hint to subscribers map in ir/store.go - Add capacity hint to activeStreams map in xds/server.go - Add capacity hint to snapshots map in xds/snapshot_proto_cache.go
1 parent 9bd0ab8 commit f7ce96c

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

internal/admin/server_ai.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type AICostTrend struct {
7777
var (
7878
aiTotalTokens atomic.Uint64
7979
aiTotalRequests atomic.Uint64
80-
aiServices = make(map[string]*AIServiceSummary)
80+
aiServices = make(map[string]*AIServiceSummary, 16)
8181
aiTokenUsage []AITokenUsage
8282
aiTraces []AITraceSummary
8383
aiModelCosts = make(map[string]float64)

internal/ir/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type SnapshotStoreHooks struct {
3131
func NewSnapshotStore(logger *slog.Logger) *SnapshotStore {
3232
return &SnapshotStore{
3333
logger: logger,
34-
subscribers: make(map[int]*snapshotSubscriber),
34+
subscribers: make(map[int]*snapshotSubscriber, 8),
3535
}
3636
}
3737

internal/xds/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func New(
8484
protoCache: newSnapshotProtoCache(nil),
8585
serverOptions: serverOptions,
8686
shutdownCh: make(chan struct{}),
87-
activeStreams: make(map[string]*streamRegistration),
87+
activeStreams: make(map[string]*streamRegistration, 64),
8888
}, nil
8989
}
9090

internal/xds/snapshot_proto_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (c *snapshotProtoCache) get(snapshot *ir.Snapshot, profile projectionProfil
3737
c.snapshots = nil
3838
}
3939
if c.snapshots == nil {
40-
c.snapshots = make(map[string]*controlv1.ConfigSnapshot)
40+
c.snapshots = make(map[string]*controlv1.ConfigSnapshot, 32)
4141
}
4242
cached := c.snapshots[profile.projectionKey]
4343
if cached == nil {

0 commit comments

Comments
 (0)