Skip to content

feat: prefetch the next block while scrolling SpikeInterface traces - #1

Closed
galenlynch wants to merge 1 commit into
feat/spikeinterface-reader-syncfrom
feat/spikeinterface-reader-prefetch
Closed

galenlynch wants to merge 1 commit into
feat/spikeinterface-reader-syncfrom
feat/spikeinterface-reader-prefetch

Conversation

@galenlynch

Copy link
Copy Markdown
Member

Builds on cortex-lab#68. With the SpikeInterface reader, scrolling the trace view stalls each time the window reaches a block that hasn't been computed yet. This computes the next block on a background thread while you scroll, so most steps are served from the cache.

Prefetch only happens when a read continues the previous one, and only in the direction of travel. Any other read, like a waveform snippet, cancels pending prefetches and prefetches nothing, so random access does no extra work. A requested block is never queued behind a prefetch, and a failed prefetch is dropped rather than cached. close() stops the thread. Pass prefetch=False to turn it
off.

benchmarks/benchmark_spikeinterface_reader.py uses a fake recording that takes 0.2 s plus 0.5 s per second of data on each call. Scrolling 100 steps goes from 13.8 s to 11.4 s, with one slow read instead of six. 100 random snippet reads take the same time with and without prefetch.

Scrolling a remote or preprocessed recording stalls each time the
window enters a block not yet computed. A read that continues the
previous one now starts computing the next block in the direction of
travel on a background thread. Reads that jump, such as waveform
snippets, prefetch nothing and cancel pending prefetches, so random
access does no extra work, and a requested block is computed in the
calling thread rather than queued behind prefetches. A failed prefetch
is dropped, so it does not make its block unreadable. close() stops the
thread pool.

benchmarks/benchmark_spikeinterface_reader.py, 384 channels at 30 kHz
with 0.2 s latency plus 0.5 s per second of data per call:

  pattern   prefetch  total   mean read  reads > 0.1 s  get_traces
  scroll    off       13.78s  0.038s     6              6
  scroll    on        11.44s  0.014s     1              7
  snippets  off       47.38s  0.474s     100            102
  snippets  on        46.89s  0.469s     100            102

Scrolling is 100 steps of 10% of a 0.25 s window with 0.1 s pauses; the
one slow read left is the first. Snippets are 100 reads of 82 samples.
@galenlynch galenlynch closed this Oct 22, 2026
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.

1 participant