Skip to content

Avoid materializing entire time vector from zarr for time_to_sample_index#4620

Merged
alejoe91 merged 2 commits into
SpikeInterface:mainfrom
grahamfindlay:perf/lazy_time_to_sample_index
Jul 14, 2026
Merged

Avoid materializing entire time vector from zarr for time_to_sample_index#4620
alejoe91 merged 2 commits into
SpikeInterface:mainfrom
grahamfindlay:perf/lazy_time_to_sample_index

Conversation

@grahamfindlay

Copy link
Copy Markdown
Contributor

np.searchsorted is fine for mem-maps, but for out-of-core arrays (zarr) it reads the whole time vector (even if a zarr.Array) into memory. Bisecting instead reads O(log N) elements, which saves an order of magnitude of RAM for long recordings.

…ndex

`np.searchsorted` is fine for mem-maps, but for out-of-core arrays (zarr) it reads
the whole time vector (even if a `zarr.Array`) into memory. Bisecting instead reads
O(log N) elements, which saves an order of magnitude of RAM for long recordings.
"""
grahamfindlay added a commit to grahamfindlay/spikeinterface that referenced this pull request Jun 16, 2026
@alejoe91

Copy link
Copy Markdown
Member

Stumbled upon the same issue yesterday!!

Elegant solution :)

@alejoe91 alejoe91 added core Changes to core module performance Performance issues/improvements labels Jun 25, 2026
@grahamfindlay

Copy link
Copy Markdown
Contributor Author

@alejoe91
I am pretty sure that this failing test has nothing to do with the PR. I think it is because test_pipeline_equiv_to_step calls multiple preprocessors (e.g. detect_and_remove_artifacts, detect_and_interpolate_bad_channels) that are nondeterministic without seeding them. Pick any unseeded nondeterministic preprocessor, call it twice and test the results for equivalence, and if you do it enough times, you'll get a failure.

Pretty sure this is hitting #4601 too. Both safe to merge. I can work on a PR to fix the test.

@alejoe91 alejoe91 merged commit 2e04b1e into SpikeInterface:main Jul 14, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes to core module performance Performance issues/improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants