perf(weed/topology): preallocate the disk volume snapshot (#10609)

Disk.GetVolumes copies the disk's whole volume map into a fresh slice, and every
caller that walks a node's volumes goes through it: the writable-volume refresh
loop every few seconds, ToTopologyInfo on each VolumeList, telemetry, and node
unregistration. Growing from nil reallocates and copies about twice the final
size each time, which at 100k volumes per disk is 60MB of garbage per call.

BenchmarkSyncDataNodeRegistration/100000Volumes  199670102 B/op -> 137728051 B/op
This commit is contained in:
Chris Lu
2026-08-07 00:30:28 -07:00
committed by GitHub
parent 2ec899bdee
commit 1d8d9570eb
+1
View File
@@ -204,6 +204,7 @@ func (d *Disk) doAddOrUpdateVolume(v storage.VolumeInfo) (isNew, isChanged bool)
func (d *Disk) GetVolumes() (ret []storage.VolumeInfo) {
d.RLock()
ret = make([]storage.VolumeInfo, 0, len(d.volumes))
for _, v := range d.volumes {
ret = append(ret, v)
}