From 228e850da14a225d3d19280ce360d9b08667cf44 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 7 Aug 2026 01:14:34 -0700 Subject: [PATCH] perf(weed/topology): preallocate the client-facing topology snapshots (#10615) * perf(weed/topology): preallocate the /dir/status volume list ToVolumeMap boxes every volume on a node into an []interface{} grown from nil, so the slice reallocates its way up alongside the boxing. The count is known. * perf(weed/topology): preallocate the volume id list sent to clients Every filer, s3 gateway, and mount that connects to the master gets one VolumeLocation per data node carrying that node's whole volume id list, grown from nil. The count is known. The ec ids are left alone: shards of one volume can span disks, so the shard count is an upper bound on the deduped vid count, not the count itself. --- weed/topology/topology_info.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/weed/topology/topology_info.go b/weed/topology/topology_info.go index dd1f59d29..1c9bfa6b9 100644 --- a/weed/topology/topology_info.go +++ b/weed/topology/topology_info.go @@ -72,8 +72,9 @@ func (t *Topology) ToVolumeMap() interface{} { dataNodes := make(map[NodeId]interface{}) for _, d := range rack.Children() { dn := d.(*DataNode) - var volumes []interface{} - for _, v := range dn.GetVolumes() { + dnVolumes := dn.GetVolumes() + volumes := make([]interface{}, 0, len(dnVolumes)) + for _, v := range dnVolumes { volumes = append(volumes, v) } dataNodes[d.Id()] = volumes @@ -99,7 +100,9 @@ func (t *Topology) ToVolumeLocations() (volumeLocations []*master_pb.VolumeLocat DataCenter: dn.GetDataCenterId(), GrpcPort: uint32(dn.GrpcPort), } - for _, v := range dn.GetVolumes() { + dnVolumes := dn.GetVolumes() + volumeLocation.NewVids = make([]uint32, 0, len(dnVolumes)) + for _, v := range dnVolumes { volumeLocation.NewVids = append(volumeLocation.NewVids, uint32(v.Id)) } // A single EC volume's shards can live on multiple disks of