Skip to content

ORC-614: [C++] Implement efficient seek() in decompression streams - #695

Merged
dongjoon-hyun merged 2 commits into
apache:mainfrom
wgtmac:ORC-614
May 6, 2021
Merged

dongjoon-hyun merged 2 commits into
apache:mainfrom
wgtmac:ORC-614

Conversation

@wgtmac

@wgtmac wgtmac commented May 5, 2021 •

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

The current implementation of ZlibDecompressionStream::seek and
BlockDecompressionStream::seek resets the state of the decompressor
and the underlying file reader and throws away their buffers.

Why are the changes needed?

This commit introduces two optimizations which rely on reusing
the buffers that still contain useful data, and therefore reducing
the time spent reading/uncompressing the buffers again.

The first case is when the seeked position is already read
and decompressed into the output stream.

The second case is when the seeked position is already read from
the input stream, but has not been decompressed yet, ie. it's
not in the output stream.

How was this patch tested?

Tests:

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the fix. BTW, is this applicable to branch-1.6 too, @wgtmac ?

@wgtmac

wgtmac commented May 6, 2021

Copy link
Copy Markdown
Member Author

Thank you for the fix. BTW, is this applicable to branch-1.6 too, @wgtmac ?

@dongjoon-hyun No, the main branch has an innegligible refactoring of the DecompressionStream which does not exist in the branch-1.6. So I suppose this fix can only work here.

@dongjoon-hyun

Copy link
Copy Markdown
Member

Got it. Thank you for the explanation.

Comment thread c++/src/Compression.cc Outdated
void DecompressionStream::seek(PositionProvider& position) {
// clear state to force seek to read from the right position
size_t seekedPosition = position.current();
// Case 3.: the seeked position is the one that is currently buffered and

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems that this is 1 at line 536. Shall we match the number by changing this Case 3.: -> Case 1:?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread c++/src/Compression.cc Outdated
inputBuffer
= inputBufferStart + (seekedPosition - inputBufferStartPosition);
} else {
// Case 1.: The seeked position is not in the input buffer, here we are

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto. This looks like 3. It is not read yet from the inputstream..
Switching from Case 1.: to Case 3: will be better. WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread c++/src/Compression.cc Outdated
size_t remainingLength;

// the last buffer returned from the input
const char* inputBufferStart;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit. Shall we match with the coding style with the existing line 371 and 372?

- const char* inputBufferStart;
+ const char *inputBufferStart;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I left a few comments. BTW, do you think it's possible to have a simple test case for this?

Also, cc @pgaref

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for updating, @wgtmac . +1, LGTM.

@dongjoon-hyun
dongjoon-hyun merged commit 10795f3 into apache:main May 6, 2021
@dongjoon-hyun

Copy link
Copy Markdown
Member

Merged to main for Apache ORC 1.7.0.

@wgtmac
wgtmac deleted the ORC-614 branch February 23, 2022 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants