Skip to content

Commit 5654448

Browse files
committed
Use shallow copies instead of deepcopy in Learner2D.__getstate__
Key-level mutations (stack pops/inserts) are all that restore() needs to roll back; values are never mutated in place. A deepcopy of the full data dict would add O(npoints) allocation to every ask(tell_pending=False) call and to pickling.
1 parent 0c8774a commit 5654448

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎adaptive/learner/learner2D.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import warnings
55
from collections import OrderedDict
66
from collections.abc import Callable, Iterable
7-
from copy import copy, deepcopy
7+
from copy import copy
88
from math import sqrt
99

1010
import cloudpickle
@@ -897,8 +897,8 @@ def __getstate__(self):
897897
cloudpickle.dumps(self.function),
898898
self.bounds,
899899
self.loss_per_triangle,
900-
deepcopy(self._stack),
901-
deepcopy(self._get_data()),
900+
self._stack.copy(),
901+
self._get_data().copy(),
902902
)
903903

904904
def __setstate__(self, state):

0 commit comments

Comments
 (0)