From f8351de842bcd7de7691ef50399952cb1138e52f Mon Sep 17 00:00:00 2001 From: Tim Beyer <35711942+TimFelixBeyer@users.noreply.github.com> Date: Tue, 27 Jun 2023 01:13:00 +0800 Subject: [PATCH] Speed up Duration deepcopy Instead of updating the components during deepcopy (which is expensive), we defer this update until it is actually needed and just copy the object for now. This speeds up tasks that use derivations (e.g. `quantize`) by up to 30% on my machine. --- music21/duration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/music21/duration.py b/music21/duration.py index 7b49bdb926..a406872917 100644 --- a/music21/duration.py +++ b/music21/duration.py @@ -1807,7 +1807,7 @@ def __deepcopy__(self, memo): Don't copy client when creating ''' if self._componentsNeedUpdating: - self._updateComponents() + return common.defaultDeepcopy(self, memo, ignoreAttributes={'client'}) if (len(self._components) == 1 and self._dotGroups == (0,)