Skip to content

Speed up select_periods and get_data(periods=...) by finding each period's spikes with searchsorted - #4940

Open
grahamfindlay wants to merge 1 commit into
SpikeInterface:mainfrom
grahamfindlay:select-periods-mask-searchsorted
Open

grahamfindlay wants to merge 1 commit into
SpikeInterface:mainfrom
grahamfindlay:select-periods-mask-searchsorted

Conversation

@grahamfindlay

Copy link
Copy Markdown
Collaborator

select_sorting_periods_mask compares every period against all of its unit's spikes. With many periods per unit this is slow. On one of our 48 h sortings (~140 M spikes, ~3,700 periods), a single call takes 88 s. Multiple this the number of quality metrics that all call it repeatedly (to build the same mask -- a bit inefficient), and it blows up. Of the ~45 minutes that it took to compute 14 quality metrics on these data, around a third of it (15 min) was spent just in select_sorting_periods_mask.

The good news: Since each unit's spike train is sorted, the spikes inside a period form one contiguous slice. With binary search (np.searchsorted), it is fast and easy to find the slice borders.

I haven't re-run the quality metrics on the 48 h sorting, but I did a test to get a rough sense of the timing improvement. With 50 units at 50 Hz for 1 h (9 M spikes) and 74 periods per unit, select_periods drops from 2.3 s to 0.27 s. So on the 48 h I expect it to cut >13 min off the quality metric computation time.

@grahamfindlay grahamfindlay added core Changes to core module performance Performance issues/improvements labels Nov 12, 2026
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.

1 participant