Skip to content

Avoid copying all epochs data in GetEpochsMixin._getitem - #14262

Merged
larsoner merged 2 commits into
mne-tools:mainfrom
larsoner:epochs-getitem-copy
Sep 1, 2026
Merged

Avoid copying all epochs data in GetEpochsMixin._getitem#14262
larsoner merged 2 commits into
mne-tools:mainfrom
larsoner:epochs-getitem-copy

Conversation

@larsoner

@larsoner larsoner commented Sep 1, 2026

Copy link
Copy Markdown
Member

Fixes a slowdown introduced in #11282 where epochs[...] required a deepcopy of the entire ._data object (it got rid of a self._data = None trick to make checker happy) -- fix it a different way that still satisfies the checks and doesn't end up requiring a copy of the data. On main, [epochs[ii] for ii in len(epochs] copies the entire data array len(epochs) times. On this PR, it only copies what is actually taken/used. It makes the checks happy by setting self._data = data[:0] which copies instantly and makes the checks happy, replaces it on self in a finally, and then replaces it on inst later before returning inst.

Also tacks on a tiny fix with deepcopy where we didn't add self to the memodict so infinite recursion was possible in some corner cases (e.g., via info["temp"] = info). Probably not likely people will actually hit this, but setting memodict properly is best practice so might as well.

Changes investigated and drafted by Claude Fable 5 and reviewed / iterated by me (while looking at MNE-BIDS-Pipeline bottlenecks).

@larsoner larsoner added this to the 1.13 milestone Sep 1, 2026
@larsoner

larsoner commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Tacked on a fix for module-level test timings that has been broken since using xdist (I wanted to see where most of the time is going on macOS and realized the info was gone 🤦 )

@drammock
drammock enabled auto-merge (squash) September 1, 2026 17:15
@larsoner
larsoner disabled auto-merge September 1, 2026 18:05
@larsoner

larsoner commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

scientific-python-nightly-wheels repo is having a bad day, merging manually

@larsoner
larsoner merged commit a93adbd into mne-tools:main Sep 1, 2026
44 of 49 checks passed
@larsoner
larsoner deleted the epochs-getitem-copy branch September 1, 2026 18:06
larsoner added a commit to larsoner/mne-python that referenced this pull request Sep 2, 2026
* upstream/main: (22 commits)
  Avoid copying all epochs data in GetEpochsMixin._getitem (mne-tools#14262)
  Add Report.save(only_if_changed=True) (mne-tools#14261)
  Add jamica to related software [ci skip] (mne-tools#14260)
  Remove debugging cruft (mne-tools#14259)
  ENH: add Raw annotation span conversion (mne-tools#14240)
  Interactive dipole fitting: add STC mesh controls (mne-tools#14256)
  Document code principles in AGENTS.md (mne-tools#14239)
  MAINT: Update dependency specifiers (mne-tools#14257)
  [dependabot]: Bump the actions group with 2 updates (mne-tools#14258)
  ENH: Add JAMICA as an ICA method (mne-tools#14247)
  Reuse the MEF session across reads (mne-tools#14254)
  Read KIT data in cache-sized blocks (mne-tools#14255)
  Read EGI simple-binary event channels in blocks (mne-tools#14250)
  Decode Persyst and Nihon Kohden data in cache-sized blocks (mne-tools#14251)
  Normalize byte order before calibrating strided integer buffers (mne-tools#14252)
  Speed up EDF and BDF reading (mne-tools#14237)
  ENH: Add Forward-based projection reconstruction (mne-tools#14235)
  Read Artemis123, Curry, EEGLAB, Eximia, FIL and NSx in cache-sized blocks (mne-tools#14246)
  Remove rotating dipoles capability from interactive dipole fitting GUI (mne-tools#14243)
  Read BrainVision data in cache-sized blocks [ci skip] (mne-tools#14241)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants