You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by do...@apache.org on 2024/01/03 13:50:55 UTC
(spark) branch master updated: [SPARK-46567][CORE] Remove ThreadLocal for ReadAheadInputStream
This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 3b1d843da2de [SPARK-46567][CORE] Remove ThreadLocal for ReadAheadInputStream
3b1d843da2de is described below
commit 3b1d843da2de524c781757b4823cc8b8e7d2f5f7
Author: beliefer <be...@163.com>
AuthorDate: Wed Jan 3 05:50:44 2024 -0800
[SPARK-46567][CORE] Remove ThreadLocal for ReadAheadInputStream
### What changes were proposed in this pull request?
This PR propose to remove `ThreadLocal` for `ReadAheadInputStream`.
### Why are the changes needed?
`ReadAheadInputStream` has a field `oneByte` declared as `TheadLocal`.
In fact, `oneByte` only used in read.
We can remove it by the way that the closure of local variables in instance methods can provide thread safety guarantees.
On the other hand, the `TheadLocal` occupies a certain amount of space in the heap and there are allocation and GC costs.
### Does this PR introduce _any_ user-facing change?
'No'.
### How was this patch tested?
Exists test cases.
### Was this patch authored or co-authored using generative AI tooling?
'No'.
Closes #44563 from beliefer/SPARK-46567.
Authored-by: beliefer <be...@163.com>
Signed-off-by: Dongjoon Hyun <dh...@apple.com>
---
core/src/main/java/org/apache/spark/io/ReadAheadInputStream.java | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/core/src/main/java/org/apache/spark/io/ReadAheadInputStream.java b/core/src/main/java/org/apache/spark/io/ReadAheadInputStream.java
index 1b76aae8dd22..33dfa4422906 100644
--- a/core/src/main/java/org/apache/spark/io/ReadAheadInputStream.java
+++ b/core/src/main/java/org/apache/spark/io/ReadAheadInputStream.java
@@ -89,8 +89,6 @@ public class ReadAheadInputStream extends InputStream {
private final Condition asyncReadComplete = stateChangeLock.newCondition();
- private static final ThreadLocal<byte[]> oneByte = ThreadLocal.withInitial(() -> new byte[1]);
-
/**
* Creates a <code>ReadAheadInputStream</code> with the specified buffer size and read-ahead
* threshold
@@ -247,7 +245,7 @@ public class ReadAheadInputStream extends InputStream {
// short path - just get one byte.
return activeBuffer.get() & 0xFF;
} else {
- byte[] oneByteArray = oneByte.get();
+ byte[] oneByteArray = new byte[1];
return read(oneByteArray, 0, 1) == -1 ? -1 : oneByteArray[0] & 0xFF;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org