Commit 3851cb5
[SPARK-56302][CORE] Free task result memory eagerly during serialization on executor
### What changes were proposed in this pull request?
Eagerly null intermediate objects during task result serialization in `Executor` to reduce peak heap memory usage.
During result serialization in `TaskRunner.run()`, three representations of the result coexist on the heap simultaneously:
1. `value` — the raw task result object from `task.run()`
2. `valueByteBuffer` — first serialization of the result
3. `serializedDirectResult` — second serialization wrapping the above into a `DirectTaskResult`
Each becomes dead as soon as the next is produced, but none were released.
This PR nulls each reference as soon as it's no longer needed:
- `value = null` after serializing into `valueByteBuffer`
- `valueByteBuffer = null` and `directResult = null` after re-serializing into `serializedDirectResult`
All changes are confined to the executor side within `TaskRunner.run()`, where the variables are local and not exposed to other components.
### Why are the changes needed?
For tasks returning large results (e.g. `collect()` on large datasets), the redundant copies can roughly triple peak memory during serialization, increasing GC pressure or causing executor OOM. Eagerly freeing dead references lets the GC reclaim memory sooner.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing UTs
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code v2.1.88
Closes apache#55110 from ivoson/free-result-memory-asap.
Lead-authored-by: Tengfei Huang <[email protected]>
Co-authored-by: Tengfei Huang <[email protected]>
Signed-off-by: yangjie01 <[email protected]>1 parent 4018cc7 commit 3851cb5
File tree
1 file changed
+11
-3
lines changed- core/src/main/scala/org/apache/spark/executor
1 file changed
+11
-3
lines changedLines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
883 | 884 | | |
884 | 885 | | |
885 | 886 | | |
886 | | - | |
| 887 | + | |
887 | 888 | | |
888 | 889 | | |
889 | 890 | | |
| |||
938 | 939 | | |
939 | 940 | | |
940 | 941 | | |
941 | | - | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
942 | 945 | | |
943 | 946 | | |
944 | 947 | | |
| |||
982 | 985 | | |
983 | 986 | | |
984 | 987 | | |
985 | | - | |
| 988 | + | |
| 989 | + | |
986 | 990 | | |
987 | 991 | | |
988 | 992 | | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
989 | 997 | | |
990 | 998 | | |
991 | 999 | | |
| |||
0 commit comments