question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

performance hit with NWB + fancy indexing

See original GitHub issue

These lines can lead to slow reads from the NWB extractor due to fancy indexing. Whenever I do something like this, I read the full channel column and then do a fast fancy index from the ndarray in memory. It is technically wasteful, but the use case for memory mapping is to pull out relatively small chunks.

https://github.com/SpikeInterface/spikeinterface/blob/29a64a2f5024cdd11c127159c58ab84facd23af5/spikeinterface/extractors/nwbextractors.py#L226-L238

I refactored this downstream as the following. Big improvement when working with a ChannelSliceRecording

        if isinstance(channel_indices, slice):
            traces = es.data[start_frame:end_frame, channel_indices]
        else:
            # channel_indices is np.ndarray
            channel_indices = np.asarray(channel_indices)
            if channel_indices.size > 1:
                traces = es.data[start_frame:end_frame][:, channel_indices]
            else:
                traces = es.data[start_frame:end_frame, channel_indices[0]]

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
miketrumpiscommented, Apr 10, 2022

Excellent points. Certainly 100x memory waste is unacceptable, and probably slower. I will def keep using a subclass for the scenario with <<2x memory overhead and 4x-8x speedup. The not-very-helpful proposal that occurs to me here is a threshold policy (e.g. over/under 2x overhead) for automatically deciding between the two approaches.

0reactions
alejoe91commented, Aug 1, 2022

closed for inactivity

Read more comments on GitHub >

github_iconTop Results From Across the Web

Performance of various numpy fancy indexing methods, also ...
It's simple: Integer array indexing only needs to access as many elements as there are values in the index-array. That means if there...
Read more >
Fancy Indexing | Python Data Science Handbook
Fancy indexing is like the simple indexing we've already seen, but we pass arrays of indices in place of single scalars. This allows...
Read more >
Why is fancy indexing slower than flattening + flat indexing?
I recently noticed that it is faster to flatten a list of index arrays and then index the flat array than to use...
Read more >
Experimental Directory Structure (Exdir): An Alternative to HDF5 ...
However, issues with HDF5 have recently surfaced in the neuroscience ... Exdir supports all the operations supported by memmap, including fancy indexing:.
Read more >
The problem is loss of gpu performance when matrix indexing
The problem is loss of performance when indexing. Please see the test program code... You can see that as soon as the indexing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found