Skip to content

[Data] Pin fused map function for shuffle tasks - #65480

Merged
richardliaw merged 5 commits into
ray-project:masterfrom
viiccwen:data-pin-fused-map-function
Aug 21, 2026
Merged

richardliaw merged 5 commits into
ray-project:masterfrom
viiccwen:data-pin-fused-map-function

Conversation

@viiccwen

@viiccwen viiccwen commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Store a fused upstream map function once in Ray's object store when constructing ShuffleTaskSpec, then pass its ObjectRef as a top-level positional argument to pull- and push-based shuffle-map tasks.

On master, the function is stored directly in map_args and serialized with every task submission. Large captured UDF state therefore consumes object-store memory approximately in proportion to the number of shuffle-map tasks.

Benchmark

Compared master against this branch using 500,000 rows and 4 local CPUs. Every measured sample launched a fresh Ray process, asserted an already-fused physical plan, ran a fixed 0 MiB-closure warm-up, and timed only
the measured Dataset materialization. Master and fix samples were alternated in A/B/A/B order, with 10 independent samples per revision and case.

Case Master median Fix median Ratio Master IQR Fix IQR Master peak Fix peak
Pull random shuffle, 10 MiB 0.121s 0.074s 1.64x 0.119-0.132s 0.066-0.086s 104.0 MiB 13.9 MiB
Pull random shuffle, 25 MiB 0.187s 0.102s 1.84x 0.185-0.194s 0.086-0.108s 254.0 MiB 28.9 MiB
Pull random shuffle, 50 MiB 0.384s 0.113s 3.41x 0.320-0.409s 0.099-0.147s 504.0 MiB 53.9 MiB
Pull random shuffle, 100 MiB 0.640s 0.155s 4.11x 0.490-0.690s 0.134-0.186s 1004.0 MiB 103.9 MiB
Pull repartition, 100 MiB 0.426s 0.150s 2.83x 0.407-0.512s 0.127-0.239s 1004.0 MiB 103.9 MiB
Push random shuffle, 100 MiB 1.873s 0.146s 12.84x 1.411-2.485s 0.133-0.160s 1011.2 MiB 111.2 MiB
Push repartition, 100 MiB 1.527s 0.130s 11.78x 1.349-2.056s 0.120-0.139s 1011.2 MiB 111.2 MiB

Related issues

closes #65479.

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

@viiccwen
viiccwen requested a review from a team as a code owner August 14, 2026 02:20

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request optimizes ShuffleTaskSpec by storing the upstream_map_fn in the Ray object store via ray.put during initialization, preventing redundant serialization. A corresponding unit test was added to verify this behavior. The reviewer noted that the mock upstream_map_fn in the new test is defined and called with two arguments, whereas the production signature only uses a single argument, and suggested updating the test to align with the production usage.

@viiccwen
viiccwen force-pushed the data-pin-fused-map-function branch from 2c8ed37 to 0a2a763 Compare August 14, 2026 03:18
@owenowenisme owenowenisme self-assigned this Aug 14, 2026
@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Aug 14, 2026

@owenowenisme owenowenisme left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey thanks for contribution. I think the change is reasonable and this is a real bug, however this path (what we call shuffle v1) is slated for removal in an upcoming release, so I wouldn't invest more time optimizing here.

I'll approve since the fix is real and low risk, but can you drop the test as other tests is already sufficient for that?

@owenowenisme owenowenisme added the go add ONLY when ready to merge, run all tests label Aug 15, 2026
Store the fused upstream map function once in the object store and pass its ObjectRef as a top-level shuffle task argument. This avoids serializing large UDF closures for every shuffle map submission.

Signed-off-by: viiccwen <[email protected]>
@viiccwen
viiccwen force-pushed the data-pin-fused-map-function branch from 0a2a763 to ad3e125 Compare August 16, 2026 02:53
@viiccwen

Copy link
Copy Markdown
Contributor Author

Hey thanks for contribution. I think the change is reasonable and this is a real bug, however this path (what we call shuffle v1) is slated for removal in an upcoming release, so I wouldn't invest more time optimizing here.

I'll approve since the fix is real and low risk, but can you drop the test as other tests is already sufficient for that?

Thanks for feedback, I've removed it.

@owenowenisme

Copy link
Copy Markdown
Member

@viiccwen please check the failed tests

@viiccwen

Copy link
Copy Markdown
Contributor Author

@viiccwen please check the failed tests

Not caused by this PR.

ERROR: HTTP error 502 while getting ...referencing-0.35.1...
ERROR: no such package '@@py_deps_py310_referencing//'
ERROR: Build did NOT complete successfully

@richardliaw
richardliaw merged commit 138c80a into ray-project:master Aug 21, 2026
6 checks passed
@viiccwen
viiccwen deleted the data-pin-fused-map-function branch August 22, 2026 10:34
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
## Description
Store a fused upstream map function once in Ray's object store when
constructing `ShuffleTaskSpec`, then pass its `ObjectRef` as a top-level
positional argument to pull- and push-based shuffle-map tasks.

On `master`, the function is stored directly in `map_args` and
serialized with every task submission. Large captured UDF state
therefore consumes object-store memory approximately in proportion to
the number of shuffle-map tasks.

### Benchmark

Compared `master` against this branch using 500,000 rows and 4 local
CPUs. Every measured sample launched a fresh Ray process, asserted an
already-fused physical plan, ran a fixed 0 MiB-closure warm-up, and
timed only
the measured Dataset materialization. Master and fix samples were
alternated in A/B/A/B order, with 10 independent samples per revision
and case.

| Case | Master median | Fix median | Ratio | Master IQR | Fix IQR |
Master peak | Fix peak |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| Pull random shuffle, 10 MiB | `0.121s` | `0.074s` | `1.64x` |
`0.119-0.132s` | `0.066-0.086s` | `104.0 MiB` | `13.9 MiB` |
| Pull random shuffle, 25 MiB | `0.187s` | `0.102s` | `1.84x` |
`0.185-0.194s` | `0.086-0.108s` | `254.0 MiB` | `28.9 MiB` |
| Pull random shuffle, 50 MiB | `0.384s` | `0.113s` | `3.41x` |
`0.320-0.409s` | `0.099-0.147s` | `504.0 MiB` | `53.9 MiB` |
| Pull random shuffle, 100 MiB | `0.640s` | `0.155s` | `4.11x` |
`0.490-0.690s` | `0.134-0.186s` | `1004.0 MiB` | `103.9 MiB` |
| Pull repartition, 100 MiB | `0.426s` | `0.150s` | `2.83x` |
`0.407-0.512s` | `0.127-0.239s` | `1004.0 MiB` | `103.9 MiB` |
| Push random shuffle, 100 MiB | `1.873s` | `0.146s` | `12.84x` |
`1.411-2.485s` | `0.133-0.160s` | `1011.2 MiB` | `111.2 MiB` |
| Push repartition, 100 MiB | `1.527s` | `0.130s` | `11.78x` |
`1.349-2.056s` | `0.120-0.139s` | `1011.2 MiB` | `111.2 MiB` |

## Related issues
closes ray-project#65479.

## Additional information
> Optional: Add implementation details, API changes, usage examples,
screenshots, etc.

Signed-off-by: viiccwen <[email protected]>
Co-authored-by: You-Cheng Lin <[email protected]>
chia7712 pushed a commit to opensource4you/readme that referenced this pull request Oct 23, 2026
Add a nomination under `fellowship/ray/`

Suggested level: 30k

Highlights from 2026-09-01 to 2026-10-11:

- [Contribution](https://github.com/opensource4you/readme/blob/main/fellowship/ray/fellow-contribution/viiccwen/September/report.md)
- Merged 10 Ray Data PRs and filed 8 issues in 6 weeks
- Made shuffle tasks up to 12.84x faster by pinning the fused map function, so large UDF closures are no longer serialized again for every shuffle task ([#65480](ray-project/ray#65480))
- Built a memory observability series to help users avoid OOM: exported task peak USS and logical memory metrics with Grafana charts ([#65666](ray-project/ray#65666), [#66044](ray-project/ray#66044)), added a warning with a suggested memory value when it is set below 1.25x max USS ([#65512](ray-project/ray#65512)), and updated the OOM prevention docs ([#65509](ray-project/ray#65509))
- Found, reported and fixed silent data loss in hash-shuffle (V2) anti joins, where rows were dropped when the other side was empty and had an unknown schema ([#66126](ray-project/ray#66126))
- Reviewed other fellows' PRs with suggestions ([#66878](ray-project/ray#66878))
- Merged the most PRs and filed the most issues of all Ray Fellowship participants
- Solid work for an early contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data] Fused map functions are serialized with every shuffle-map task

3 participants