From 9bd1f267d2b512c9e5b25cf409dc0f77b970362d Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Tue, 24 Nov 2020 09:14:00 -0800 Subject: [PATCH] nomad: try to avoid slice resizing when batching --- nomad/node_endpoint.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nomad/node_endpoint.go b/nomad/node_endpoint.go index f795d1bd2..36a18a26f 100644 --- a/nomad/node_endpoint.go +++ b/nomad/node_endpoint.go @@ -1144,8 +1144,13 @@ func (n *Node) UpdateAlloc(args *structs.AllocUpdateRequest, reply *structs.Gene updates := n.updates evals := n.evals future := n.updateFuture - n.updates = nil - n.evals = nil + + // Assume future update patterns will be similar to + // current batch and set cap appropriately to avoid + // slice resizing. + n.updates = make([]*structs.Allocation, 0, len(updates)) + n.evals = make([]*structs.Evaluation, 0, len(evals)) + n.updateFuture = nil n.updateTimer = nil n.updatesLock.Unlock()