Skip to content

Conversation

@dongjoon-hyun
Copy link
Member

@dongjoon-hyun dongjoon-hyun commented Aug 8, 2025

What changes were proposed in this pull request?

This PR aims to use Java InputStream.readAllBytes instead of ByteStreams.toByteArray in order to improve the performance.

Why are the changes needed?

Since Java 9+, we can use readAllBytes which is roughly 30% faster than ByteStreams.toByteArray.

BEFORE (ByteStreams.toByteArray)

scala> spark.time(com.google.common.io.ByteStreams.toByteArray(new java.io.FileInputStream("/tmp/1G.bin")).length)
Time taken: 386 ms
val res0: Int = 1073741824

AFTER (InputStream.readAllBytes)

scala> spark.time(new java.io.FileInputStream("/tmp/1G.bin").readAllBytes().length)
Time taken: 248 ms
val res0: Int = 1073741824

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Pass the CIs.

Was this patch authored or co-authored using generative AI tooling?

No.

@dongjoon-hyun
Copy link
Member Author

Thank you, @yaooqinn ~

@dongjoon-hyun
Copy link
Member Author

Merged to master for Apache Spark 4.1.0.

@dongjoon-hyun dongjoon-hyun deleted the SPARK-53191 branch August 8, 2025 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants