BaseSorting.register_recording stores the recording by reference (self._recording = recording). Any mutation to the recording object (setting times, shifting times, setting probes, changing properties) is visible through the sorting. This makes it hard to reason about ownership: code that modifies a recording may not know a sorting is sharing it, and code that operates on a sorting may not intend to mutate someone else's recording.
I think that we should copy the recording at registration time so that it serves as a snapshot. This way, we might want to mutate something of the recording in the registration without affecting it or vice-versa. Recordings are lazy wrappers (file paths, memmap references, channel metadata), so the copy is cheap. Was the current by-reference behavior intentional?
This came up while thinking about adding time manipulation methods (like shift_times) to BaseSorting. If the sorting delegates to a shared recording, calling sorting.shift_times() would mutate the original recording as a side effect. With a copied recording, the sorting could safely manipulate its own time state without affecting anything external.
BaseSorting.register_recordingstores the recording by reference (self._recording = recording). Any mutation to the recording object (setting times, shifting times, setting probes, changing properties) is visible through the sorting. This makes it hard to reason about ownership: code that modifies a recording may not know a sorting is sharing it, and code that operates on a sorting may not intend to mutate someone else's recording.I think that we should copy the recording at registration time so that it serves as a snapshot. This way, we might want to mutate something of the recording in the registration without affecting it or vice-versa. Recordings are lazy wrappers (file paths, memmap references, channel metadata), so the copy is cheap. Was the current by-reference behavior intentional?
This came up while thinking about adding time manipulation methods (like
shift_times) toBaseSorting. If the sorting delegates to a shared recording, callingsorting.shift_times()would mutate the original recording as a side effect. With a copied recording, the sorting could safely manipulate its own time state without affecting anything external.