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

feat: Optimize PrestoSerializer decompress buffer #11836

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jinchengchenghh
Copy link
Contributor

@jinchengchenghh jinchengchenghh commented Dec 12, 2024

Read the BufferInputStream by new added function readBytes to avoid copying from the buffer cache. Extract the uncompress process to a new function can help release the compressed buffer in time.

FileInputStream reuse the read buffer, so we can get the IOBuf without copy only if the required bytes is in one buffer, which is not the common case, so I don't do the optimization for it.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 12, 2024
Copy link

netlify bot commented Dec 12, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit ce58686
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/675d2933cf055000082ae661

@jinchengchenghh jinchengchenghh changed the title feat: Optimize PrestoSerializer compress buffer feat: Optimize PrestoSerializer decompress buffer for BufferInputStream Dec 13, 2024
@jinchengchenghh
Copy link
Contributor Author

Can you help review again? Thanks! @Yuhta

auto newBuf = folly::IOBuf::wrapBuffer(
current_->buffer + current_->position, readBytes);
if (result) {
result->prev()->appendChain(std::move(newBuf));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of buffers here is incorrect. Just do result->appendToChain(std::move(newBuf)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order is same with IOBufOutputStream::getIOBuf(), appendToChain is also OK. I will change as you say.

common::CompressionKind compressionKind,
memory::MemoryPool& pool) {
const auto codec = common::compressionKindToCodec(compressionKind);
if (dynamic_cast<BufferInputStream*>(source)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do the dynamic_cast once: if (const auto* bufferSource = dynamic_cast<BufferInputStream*>(source))

auto byteStream = createStream(byteRanges);
auto bufferStream = dynamic_cast<BufferInputStream*>(byteStream.get());
for (int offset = 0; offset < streamSize;) {
auto iobuf = bufferStream->readBytes(streamSize / 8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not testing the case one IOBuf chain cross 2 buffers. Let's cover that as well.

@jinchengchenghh jinchengchenghh changed the title feat: Optimize PrestoSerializer decompress buffer for BufferInputStream feat: Optimize PrestoSerializer decompress buffer Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants