[GLUTEN-11133][VL] Reduce on-heap memory allocation and memory copy when off-heap BHJ is enabled#11148
Conversation
…-heap BHJ is enabled This targets to fix apache#11133 by moving most on-heap allocations on the BHJ code path when `spark.gluten.velox.offHeapBroadcastBuildRelation.enabled=true`.
|
cc @zjuwangg @jinchengchenghh, please review the code change, thanks. I am benchmarking the memory footprint and will update here. |
| buffer.close(); | ||
| } | ||
|
|
||
| private synchronized void close() { |
There was a problem hiding this comment.
Please add a comment that the buffer might not released here. Looks a bit hard to understand here, but looks like we don't have a better way, maybe don't call close in toUnsafeByteArray
There was a problem hiding this comment.
Yes. I am thinking whether it's easier to understand if using Arrow's reference management instead. Let me give it a try in this PR.
There was a problem hiding this comment.
@jinchengchenghh Any thoughts about the new way: c1accf5, thanks.
| this.size = size; | ||
| } | ||
|
|
||
| public UnsafeByteArray() {} |
There was a problem hiding this comment.
Do we need this constructor?
There was a problem hiding this comment.
Yes, it's for kryo serialization.
0d002c0 to
c1accf5
Compare
|
I've updated the benchmark results in the PR description. |
|
Thanks @jinchengchenghh for the review. |
This targets to fix #11133 by moving most on-heap allocations on the BHJ code path to off-heap when
spark.gluten.velox.offHeapBroadcastBuildRelation.enabled=true.Peak On-Heap Memory Usage Benchmark
Results
Benchmark ran with TPC-DS Q64 / SF100 / -Xmx5G / 8 core Apple silicon.
Before (Off-Heap BHJ Off)
Peak heap memory usage is ~3.5GiB.
Before (Off-Heap BHJ On)
Peak heap memory usage is ~3GiB.
After (Off-Heap BHJ On)
Peak heap memory usage is ~2GiB.
Observation
In the benchmark, the PR reduces the peak heap memory usage by ~30% (from 3GiB to 2GiB).