Skip to content

[GLUTEN-11133][VL] Reduce on-heap memory allocation and memory copy when off-heap BHJ is enabled#11148

Merged
zhztheplayer merged 9 commits into
apache:mainfrom
zhztheplayer:wip-off-heap-bhj
Nov 26, 2025
Merged

[GLUTEN-11133][VL] Reduce on-heap memory allocation and memory copy when off-heap BHJ is enabled#11148
zhztheplayer merged 9 commits into
apache:mainfrom
zhztheplayer:wip-off-heap-bhj

Conversation

@zhztheplayer

@zhztheplayer zhztheplayer commented Nov 21, 2025

Copy link
Copy Markdown
Member

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.

Screenshot 2025-11-26 at 16 28 54

Before (Off-Heap BHJ On)

Peak heap memory usage is ~3GiB.

Screenshot 2025-11-26 at 16 29 04

After (Off-Heap BHJ On)

Peak heap memory usage is ~2GiB.

Screenshot 2025-11-26 at 16 29 13

Observation

In the benchmark, the PR reduces the peak heap memory usage by ~30% (from 3GiB to 2GiB).

…-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`.
@github-actions github-actions Bot added the VELOX label Nov 21, 2025
@zhztheplayer zhztheplayer changed the title [GLUTEN-11133][VL] Reduce on-heap memory allocation from BHJ when off-heap BHJ is enabled [GLUTEN-11133][VL] Reduce on-heap memory allocation when off-heap BHJ is enabled Nov 21, 2025
@zhztheplayer zhztheplayer changed the title [GLUTEN-11133][VL] Reduce on-heap memory allocation when off-heap BHJ is enabled [GLUTEN-11133][VL] Reduce on-heap memory allocation and memcopy when off-heap BHJ is enabled Nov 21, 2025
@zhztheplayer zhztheplayer changed the title [GLUTEN-11133][VL] Reduce on-heap memory allocation and memcopy when off-heap BHJ is enabled [GLUTEN-11133][VL] Reduce on-heap memory allocation and memory copy when off-heap BHJ is enabled Nov 21, 2025
@zhztheplayer
zhztheplayer marked this pull request as ready for review November 24, 2025 15:18
@zhztheplayer

zhztheplayer commented Nov 25, 2025

Copy link
Copy Markdown
Member Author

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@zhztheplayer zhztheplayer Nov 25, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jinchengchenghh Any thoughts about the new way: c1accf5, thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

this.size = size;
}

public UnsafeByteArray() {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this constructor?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's for kryo serialization.

@jinchengchenghh jinchengchenghh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@zhztheplayer

Copy link
Copy Markdown
Member Author

I've updated the benchmark results in the PR description.

@zhztheplayer

Copy link
Copy Markdown
Member Author

Thanks @jinchengchenghh for the review.

@zhztheplayer
zhztheplayer merged commit 7ddc963 into apache:main Nov 26, 2025
106 of 107 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VL] JVM heap OOM in BHJ caused by on-heap columnar batch serialization

2 participants