Skip to content

Copy recording on register_recording to avoid shared mutation #4519

Description

@h-mayorquin

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions