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

HPCC-30928 Improve compressToBuffer using LZ4 #18148

Merged
merged 1 commit into from
Jan 3, 2024
Merged
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
28 changes: 21 additions & 7 deletions system/jlib/jlzw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,22 +778,36 @@ void compressToBuffer(MemoryBuffer & out, size32_t len, const void * src, Compre
size32_t newSize = len * 4 / 5; // Copy if compresses less than 80% ...
Owned<ICompressor> compressor = handler->getCompressor(options);
void *newData = out.reserve(newSize);
try
if (compressor->supportsBlockCompression())
{
compressor->open(newData, newSize);
if (compressor->write(src, len)==len)
size32_t compressedLen = compressor->compressBlock(newSize, newData, len, src);
if (compressedLen != 0)
{
compressor->close();
size32_t compressedLen = compressor->buflen();
out.setWritePos(originalLength + sizeof(byte));
out.append(compressedLen);
out.setWritePos(originalLength + sizeof(byte) + sizeof(size32_t) + compressedLen);
return;
}
}
catch (IException *E)
else
{
E->Release();
try
{
compressor->open(newData, newSize);
if (compressor->write(src, len)==len)
{
compressor->close();
size32_t compressedLen = compressor->buflen();
out.setWritePos(originalLength + sizeof(byte));
out.append(compressedLen);
out.setWritePos(originalLength + sizeof(byte) + sizeof(size32_t) + compressedLen);
return;
}
}
catch (IException *E)
{
E->Release();
}
}
// failed to compress...
out.setWritePos(originalLength);
Expand Down
3 changes: 2 additions & 1 deletion testing/unittests/unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ class compressToBufferTest : public CppUnit::TestFixture
"HelloHelloHelloHelloHelloHelloHelloHelloHelloHello";
assertex(len <= strlen(in));
MemoryBuffer compressed;
CCycleTimer start;
compressToBuffer(compressed, len, in, method, options);
bool ret;
if (compressed.length() == len+5)
Expand All @@ -1102,7 +1103,7 @@ class compressToBufferTest : public CppUnit::TestFixture
else
{
if (!prevResult)
DBGLOG("compressToBuffer %x size %u compressed to %u", (byte) method, len, compressed.length());
DBGLOG("compressToBuffer %x size %u compressed to %u in %lluns", (byte) method, len, compressed.length(), start.elapsedNs());
ret = true;
}
CPPUNIT_ASSERT(compressed.length() <= len+5);
Expand Down
Loading