From e611b0ccb01b957a4181656898f1fd235f9d49af Mon Sep 17 00:00:00 2001 From: Dirk Schumacher Date: Thu, 16 May 2024 23:11:48 +0200 Subject: [PATCH] Reduce allocations when applying operators --- solve_solver.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/solve_solver.go b/solve_solver.go index 39779cb..a5e4ad2 100644 --- a/solve_solver.go +++ b/solve_solver.go @@ -281,14 +281,11 @@ func (s *solveImpl) Solve( for iteration := 0; iteration < solveOptions.Iterations; iteration++ { solveInformation.iteration = iteration solveInformation.deltaScore = 0.0 - solveInformation.solveOperators = make( - SolveOperators, - 0, - len(s.solveOperators), - ) - + // we do not clear the elements of solveOperators as they are + // stable across iterations. We do not risk a memory leak here. + solveInformation.solveOperators = solveInformation.solveOperators[:0] s.solveEvents.Iterating.Trigger(solveInformation) - for _, solveOperator := range s.SolveOperators() { + for _, solveOperator := range s.solveOperators { select { case <-ctx.Done(): s.solveEvents.ContextDone.Trigger(solveInformation)