Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix perf issue in text format reader #3589

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Source/Readers/CNTKTextFormatReader/TextParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ typename TextParser<ElemType>::SequenceBuffer TextParser<ElemType>::LoadSequence
{
size_t fileOffset = sequenceDsc.OffsetInChunk() + chunkOffsetInFile;

auto cachedSequencePos = m_fileOffsetToSequenceBuffer.find(fileOffset);
if (cachedSequencePos != m_fileOffsetToSequenceBuffer.end())
{
return cachedSequencePos->second;
}

m_fileReader->SetFileOffset(fileOffset);

size_t bytesToRead = sequenceDsc.SizeInBytes();
Expand Down Expand Up @@ -430,6 +436,8 @@ typename TextParser<ElemType>::SequenceBuffer TextParser<ElemType>::LoadSequence
}

FillSequenceMetadata(sequence, { sequenceDsc.m_key, 0 });

m_fileOffsetToSequenceBuffer[fileOffset] = sequence;
return sequence;
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Readers/CNTKTextFormatReader/TextParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "TextConfigHelper.h"
#include "Index.h"
#include "CorpusDescriptor.h"
#include <unordered_map>

namespace CNTK {

Expand Down Expand Up @@ -135,6 +136,7 @@ class TextParser : public DataDeserializerBase {
bool m_cacheIndex;
unsigned int m_numRetries; // specifies the number of times an unsuccessful
// file operation should be repeated (default value is 5).
std::unordered_map<size_t, SequenceBuffer> m_fileOffsetToSequenceBuffer;

// Corpus descriptor.
CorpusDescriptorPtr m_corpus;
Expand Down