Skip to content

Commit 983de0c

Browse files
committed
Performance improvements
1 parent 3f4aa3c commit 983de0c

7 files changed

Lines changed: 16 additions & 24 deletions

File tree

Source/Plugins/KWIKFormat/RecordEngine/HDF5FileFormat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#endif
4242

4343
#ifndef TIMESTAMP_CHUNK_SIZE
44-
#define TIMESTAMP_CHUNK_SIZE 4
44+
#define TIMESTAMP_CHUNK_SIZE 16
4545
#endif
4646

4747
#define MAX_TRANSFORM_SIZE 512
@@ -101,7 +101,7 @@ int HDF5FileBase::open(bool newfile, int nChans)
101101
FileAccPropList props = FileAccPropList::DEFAULT;
102102
if (nChans > 0)
103103
{
104-
props.setCache(0, 809, 8 * 2 * CHUNK_XSIZE * nChans, 1);
104+
props.setCache(0, 1667, 2 * 8 * 2 * CHUNK_XSIZE * nChans, 1);
105105
//std::cout << "opening HDF5 " << getFileName() << " with nchans: " << nChans << std::endl;
106106
}
107107

Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
#include "HDF5Recording.h"
2525
#define MAX_BUFFER_SIZE 40960
26-
#define CHANNEL_TIMESTAMP_PREALLOC_SIZE 16
26+
#define CHANNEL_TIMESTAMP_PREALLOC_SIZE 128
27+
#define CHANNEL_TIMESTAMP_MIN_WRITE 32
2728
#define TIMESTAMP_EACH_NSAMPLES 1024
2829

2930
HDF5Recording::HDF5Recording() : processorIndex(-1), hasAcquired(false), bufferSize(MAX_BUFFER_SIZE)
@@ -187,15 +188,6 @@ void HDF5Recording::closeFiles()
187188
channelLeftOverSamples.clear();
188189
}
189190

190-
void HDF5Recording::startChannelBlock()
191-
{
192-
int nCh = channelTimestampArray.size();
193-
for (int i = 0; i < nCh; ++i)
194-
{
195-
channelTimestampArray[i]->clearQuick();
196-
}
197-
}
198-
199191
void HDF5Recording::writeData(int writeChannel, int realChannel, const float* buffer, int size)
200192
{
201193
if (size > bufferSize) //Shouldn't happen, and if it happens it'll be slow, but better this than crashing. Will be reset on reset.
@@ -232,17 +224,18 @@ void HDF5Recording::writeData(int writeChannel, int realChannel, const float* bu
232224
channelLeftOverSamples.set(writeChannel, (size + sampleOffset) % TIMESTAMP_EACH_NSAMPLES);
233225
}
234226

235-
void HDF5Recording::endChannelBlock()
227+
void HDF5Recording::endChannelBlock(bool lastBlock)
236228
{
237229
int nCh = channelTimestampArray.size();
238230
for (int ch = 0; ch < nCh; ++ch)
239231
{
240232
int tsSize = channelTimestampArray[ch]->size();
241-
if (tsSize > 0)
233+
if ((tsSize > 0) && ((tsSize > CHANNEL_TIMESTAMP_MIN_WRITE) || lastBlock))
242234
{
243235
int realChan = getRealChannel(ch);
244236
int index = processorMap[getChannel(realChan)->recordIndex];
245237
fileArray[index]->writeTimestamps(channelTimestampArray[ch]->getRawDataPointer(), tsSize, ch);
238+
channelTimestampArray[ch]->clearQuick();
246239
}
247240
}
248241
}

Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class HDF5Recording : public RecordEngine
4343
void registerProcessor(const GenericProcessor* processor) override;
4444
void resetChannels() override;
4545
void startAcquisition() override;
46-
void startChannelBlock() override;
47-
void endChannelBlock() override;
46+
void endChannelBlock(bool lastBlock) override;
4847

4948
static RecordEngineManager* getEngineManager();
5049
private:

Source/Processors/RecordNode/RecordEngine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ void RecordEngine::registerProcessor(const GenericProcessor* processor) {}
4444

4545
void RecordEngine::addChannel(int index, const Channel* chan) {}
4646

47-
void RecordEngine::startChannelBlock() {}
47+
void RecordEngine::startChannelBlock(bool lastBlock) {}
4848

49-
void RecordEngine::endChannelBlock() {}
49+
void RecordEngine::endChannelBlock(bool lastBlock) {}
5050

5151
Channel* RecordEngine::getChannel(int index) const
5252
{

Source/Processors/RecordNode/RecordEngine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class PLUGIN_API RecordEngine
101101

102102
/** Called by the record thread before it starts writing the channels to disk
103103
*/
104-
virtual void startChannelBlock();
104+
virtual void startChannelBlock(bool lastBlock);
105105

106106
/** Write continuous data for a channel. The raw buffer pointer is passed for speed,
107107
care must be taken to only read the specified number of bytes.
@@ -110,7 +110,7 @@ class PLUGIN_API RecordEngine
110110

111111
/** Called by the record thread after it has written a channel block
112112
*/
113-
virtual void endChannelBlock();
113+
virtual void endChannelBlock(bool lastBlock);
114114

115115
/** Write a single event to disk.
116116
*/

Source/Processors/RecordNode/RecordThread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ void RecordThread::run()
110110
m_receivedFirstBlock = false;
111111
}
112112

113-
void RecordThread::writeData(const AudioSampleBuffer& dataBuffer, int maxSamples, int maxEvents, int maxSpikes)
113+
void RecordThread::writeData(const AudioSampleBuffer& dataBuffer, int maxSamples, int maxEvents, int maxSpikes, bool lastBlock)
114114
{
115115
Array<int64> timestamps;
116116
Array<CircularBufferIndexes> idx;
117117
m_dataQueue->startRead(idx, timestamps, maxSamples);
118118
EVERY_ENGINE->updateTimestamps(timestamps);
119-
EVERY_ENGINE->startChannelBlock();
119+
EVERY_ENGINE->startChannelBlock(lastBlock);
120120
for (int chan = 0; chan < m_numChannels; ++chan)
121121
{
122122
if (idx[chan].size1 > 0)
@@ -131,7 +131,7 @@ void RecordThread::writeData(const AudioSampleBuffer& dataBuffer, int maxSamples
131131
}
132132
}
133133
m_dataQueue->stopRead();
134-
EVERY_ENGINE->endChannelBlock();
134+
EVERY_ENGINE->endChannelBlock(lastBlock);
135135

136136
std::vector<EventMessagePtr> events;
137137
int nEvents = m_eventQueue->getEvents(events, maxEvents);

Source/Processors/RecordNode/RecordThread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class RecordThread : public Thread
5252
void forceCloseFiles();
5353

5454
private:
55-
void writeData(const AudioSampleBuffer& buffer, int maxSamples, int maxEvents, int maxSpikes);
55+
void writeData(const AudioSampleBuffer& buffer, int maxSamples, int maxEvents, int maxSpikes, bool lastBlock = false);
5656

5757
const OwnedArray<RecordEngine>& m_engineArray;
5858
Array<int> m_channelArray;

0 commit comments

Comments
 (0)