SpikeInterface / SpikeInterface/spikeinterface

Copy recording on `register_recording` to avoid shared mutation

Open
#4,519 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
847
Forks
280
Avg merge
3d 9h
Merged PRs (30d)
29

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the BaseSorting.register_recording entry point and trace how the recording is stored and later accessed. Check the existing lazy wrapper behavior, including file paths, memmap references, and channel metadata, before deciding how registration should isolate mutations. Done means the ownership behavior is explicit and verified for mutations made through both the sorting and the original recording.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.