This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/main by this push:
new 6b75eb18c ORC-1595: Add a short-cut to skip tiny inputs for
`ZstdCodec.compress`
6b75eb18c is described below
commit 6b75eb18c6374eb7b445680981eea21648a4cb30
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Thu Jan 18 13:57:32 2024 -0800
ORC-1595: Add a short-cut to skip tiny inputs for `ZstdCodec.compress`
### What changes were proposed in this pull request?
For `ZstdCodec.compress`, this PR aims to add a short-cut to skip tiny
inputs which is smaller than the minimum ZStandard format.
### Why are the changes needed?
To reduce the number of JNI call.
### How was this patch tested?
Pass the CIs.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #1762 from dongjoon-hyun/ORC-1595.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
java/core/src/java/org/apache/orc/impl/ZstdCodec.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/java/core/src/java/org/apache/orc/impl/ZstdCodec.java
b/java/core/src/java/org/apache/orc/impl/ZstdCodec.java
index 8b5cd24e1..3400f2890 100644
--- a/java/core/src/java/org/apache/orc/impl/ZstdCodec.java
+++ b/java/core/src/java/org/apache/orc/impl/ZstdCodec.java
@@ -171,6 +171,12 @@ public class ZstdCodec implements CompressionCodec {
public boolean compress(ByteBuffer in, ByteBuffer out,
ByteBuffer overflow,
Options options) throws IOException {
+ int inBytes = in.remaining();
+ // Skip with minimum ZStandard format size:
+ // https://datatracker.ietf.org/doc/html/rfc8878#name-zstandard-frames
+ // Magic Number (4 bytes) + Frame Header (2 bytes) + Data Block Header (3
bytes)
+ if (inBytes < 10) return false;
+
ZstdOptions zso = (ZstdOptions) options;
zstdCompressCtx = new ZstdCompressCtx();
@@ -179,7 +185,6 @@ public class ZstdCodec implements CompressionCodec {
zstdCompressCtx.setChecksum(false);
try {
- int inBytes = in.remaining();
byte[] compressed = getBuffer((int) Zstd.compressBound(inBytes));
int outBytes = zstdCompressCtx.compressByteArray(compressed, 0,
compressed.length,