vmware / go-vcloud-director

Golang SDK for VMware Cloud Director
Other
80 stars 76 forks source link

Improve 'ipSliceDifference' function memory footprint #567

Closed Didainius closed 1 year ago

Didainius commented 1 year ago

Methods NsxtEdgeGateway.GetAllUnusedExternalIPAddresses and NsxtEdgeGateway.GetUnusedExternalIPAddresses perform computations based on netip.Addr package.

The internal function ipSliceDifference is used to allocate a new slice to hold the final results. However, the operations become quite expensive memory wise having big subnets in Edge Gateway. Optimizing this function reduced memory consumption twice (see example below)

Example information

One example was allocation /8 IPv4 subnet (16777213 IPs)

Before optimization 2 operations consumed such an amount of memory (getAllUnusedExternalIPAddresses - 7703.94MB) image

After optimization 2 operations of getAllUnusedExternalIPAddresses consume such amount (after 3853.80MB vs before 7703.94MB): image