Skip to content

[data] Fix performance degradation on iceberg data source when reading large iceberg table - #49054

Merged
raulchen merged 9 commits into
ray-project:masterfrom
jimmyxie-figma:jimmyxie/fix-iceberg-read-performance-issue-when-reading-large-table
Dec 7, 2024
Merged

raulchen merged 9 commits into
ray-project:masterfrom
jimmyxie-figma:jimmyxie/fix-iceberg-read-performance-issue-when-reading-large-table

Conversation

@jimmyxie-figma

@jimmyxie-figma jimmyxie-figma commented Dec 4, 2024 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

When reading a large iceberg table the iceberg data source hangs after creating the read tasks. The relevant log related to this issue from the console shown below. The threshold for the read function is 1MB and the actual function pickled shouldn't be bigger than a couple of KBs.

The serialized size of your read function named '<lambda>' is 6.3MB. This size relatively large. As a result, Ray might excessively spill objects during execution. To fix this issue, avoid accessing `self` or other large objects in '<lambda>'.

This PR tries two issues

  • The issue where the _get_read_task reference self, and cause the lambda function to be large in size when pickling/spilling to disk. This in term cause the iceberg data source to be extremely slow when reading large tables. The PR removes all the self reference in the _get_read_task function

  • The issue where _get_read_task lambda function excessively hit the metastore (on every task read) because Table is not pickle-able. While Catalog and Table are not pickle-able . The task reader doesn't need neither of the properties. It need FileIO and TableMetadata instead, which both happens to be pickle-able, so we are passing them explicitly to the function.

Related issue number

Checks

@jimmyxie-figma
jimmyxie-figma requested a review from a team as a code owner December 4, 2024 00:18
@jimmyxie-figma
jimmyxie-figma force-pushed the jimmyxie/fix-iceberg-read-performance-issue-when-reading-large-table branch from 7d46968 to d332431 Compare December 4, 2024 00:20
@jimmyxie-figma jimmyxie-figma changed the title Fix performance degradation on iceberg data source when reading large iceberg table [Data] Fix performance degradation on iceberg data source when reading large iceberg table Dec 4, 2024
@raulchen raulchen self-assigned this Dec 5, 2024
@alexeykudinkin alexeykudinkin added the go add ONLY when ready to merge, run all tests label Dec 5, 2024

@alexeykudinkin alexeykudinkin 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.

LGTM, minor comments

Signed-off-by: Jimmy Xie <[email protected]>
Signed-off-by: Jimmy Xie <[email protected]>
@jimmyxie-figma jimmyxie-figma changed the title [Data] Fix performance degradation on iceberg data source when reading large iceberg table [data] Fix performance degradation on iceberg data source when reading large iceberg table Dec 5, 2024
Comment on lines +205 to +208
# Get required properties for reading tasks - table IO, table metadata,
# row filter, case sensitivity,limit and projected schema. pre-apply
# them to `_get_read_task` through partial to avoid `self` reference
# which causes perfromance degradation during serialization

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.

Suggested change
# Get required properties for reading tasks - table IO, table metadata,
# row filter, case sensitivity,limit and projected schema. pre-apply
# them to `_get_read_task` through partial to avoid `self` reference
# which causes perfromance degradation during serialization
# Get required properties for reading tasks - table IO, table metadata,
# row filter, case sensitivity,limit and projected schema to pass
# them directly to `_get_read_task` to avoid capture of `self` reference
# within the closure carrying substantial overhead invoking these tasks
#
# See XXX for more context

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.

@jimmyxie-figma can you please also file a ticket outlining details of this issue (that you already capture in the description) and link it here for future code reader reference

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alexeykudinkin added a ticket to the comment

@raulchen raulchen 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!

@raulchen
raulchen merged commit 881a45d into ray-project:master Dec 7, 2024
@jimmyxie-figma
jimmyxie-figma deleted the jimmyxie/fix-iceberg-read-performance-issue-when-reading-large-table branch December 9, 2024 14:24
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Dec 17, 2024
…g large iceberg table (ray-project#49054)

## Why are these changes needed?
When reading a large iceberg table the `iceberg data source` hangs after
creating the `read tasks`. The relevant log related to this issue from
the console shown below. The threshold for the read function is 1MB and
the actual function pickled shouldn't be bigger than a couple of KBs.

```
The serialized size of your read function named '<lambda>' is 6.3MB. This size relatively large. As a result, Ray might excessively spill objects during execution. To fix this issue, avoid accessing `self` or other large objects in '<lambda>'.
```

<!-- Please give a short summary of the change and the problem this
solves. -->
This PR tries two issues
- The issue where the `_get_read_task` reference `self`, and cause the
lambda function to be large in size when pickling/spilling to disk. This
in term cause the iceberg data source to be extremely slow when reading
large tables. The PR removes all the `self` reference in the
`_get_read_task` function

- The issue where `_get_read_task` lambda function excessively hit the
metastore (on every task read) because `Table` is not pickle-able. While
`Catalog` and `Table` are not pickle-able . The task reader doesn't need
neither of the properties. It need `FileIO` and `TableMetadata` instead,
which both happens to be pickle-able, so we are passing them explicitly
to the function.

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

---------

Signed-off-by: Jimmy Xie <[email protected]>
Signed-off-by: ujjawal-khare <[email protected]>
alexeykudinkin pushed a commit that referenced this pull request Sep 4, 2025
…urce when using a large number of files (#55978)

## Why are these changes needed?

Using `FileBasedDatasource` or `ParquetDatasource` with a very large
number of files causes OOM when creating read tasks. The full list of
file paths is stored in `self`, causing it to persist to every read
task, leading to this warning:
```
The serialized size of your read function named 'read_task_fn' is 49.8MB. This size relatively large. As a result, Ray might excessively spill objects during execution. To fix this issue, avoid accessing `self` or other large objects in 'read_task_fn'.
```

When using a small number of blocks, OOM does not occur because the
large file list is not repeated so many times. But when setting high
parallelism with `override_num_blocks`, OOM occurs.

This is because the full list of paths is added to
`self._unresolved_paths`. This attribute isn't currently used anywhere
in ray. This PR removes `self._unresolved_paths` to alleviate unexpected
high memory usage with very large numbers of files.

## Related issue number

Similar to this issue with Iceberg: #49054 

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [x] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [x] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Jack Gammack <[email protected]>
sampan-s-nayak pushed a commit to sampan-s-nayak/ray that referenced this pull request Sep 8, 2025
…urce when using a large number of files (ray-project#55978)

## Why are these changes needed?

Using `FileBasedDatasource` or `ParquetDatasource` with a very large
number of files causes OOM when creating read tasks. The full list of
file paths is stored in `self`, causing it to persist to every read
task, leading to this warning:
```
The serialized size of your read function named 'read_task_fn' is 49.8MB. This size relatively large. As a result, Ray might excessively spill objects during execution. To fix this issue, avoid accessing `self` or other large objects in 'read_task_fn'.
```

When using a small number of blocks, OOM does not occur because the
large file list is not repeated so many times. But when setting high
parallelism with `override_num_blocks`, OOM occurs.

This is because the full list of paths is added to
`self._unresolved_paths`. This attribute isn't currently used anywhere
in ray. This PR removes `self._unresolved_paths` to alleviate unexpected
high memory usage with very large numbers of files.

## Related issue number

Similar to this issue with Iceberg: ray-project#49054

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [x] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [x] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Jack Gammack <[email protected]>
Signed-off-by: sampan <[email protected]>
jugalshah291 pushed a commit to jugalshah291/ray_fork that referenced this pull request Sep 11, 2025
…urce when using a large number of files (ray-project#55978)

## Why are these changes needed?

Using `FileBasedDatasource` or `ParquetDatasource` with a very large
number of files causes OOM when creating read tasks. The full list of
file paths is stored in `self`, causing it to persist to every read
task, leading to this warning:
```
The serialized size of your read function named 'read_task_fn' is 49.8MB. This size relatively large. As a result, Ray might excessively spill objects during execution. To fix this issue, avoid accessing `self` or other large objects in 'read_task_fn'.
```

When using a small number of blocks, OOM does not occur because the
large file list is not repeated so many times. But when setting high
parallelism with `override_num_blocks`, OOM occurs.

This is because the full list of paths is added to
`self._unresolved_paths`. This attribute isn't currently used anywhere
in ray. This PR removes `self._unresolved_paths` to alleviate unexpected
high memory usage with very large numbers of files.

## Related issue number

Similar to this issue with Iceberg: ray-project#49054

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [x] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [x] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Jack Gammack <[email protected]>
Signed-off-by: jugalshah291 <[email protected]>
wyhong3103 pushed a commit to wyhong3103/ray that referenced this pull request Sep 12, 2025
…urce when using a large number of files (ray-project#55978)

## Why are these changes needed?

Using `FileBasedDatasource` or `ParquetDatasource` with a very large
number of files causes OOM when creating read tasks. The full list of
file paths is stored in `self`, causing it to persist to every read
task, leading to this warning:
```
The serialized size of your read function named 'read_task_fn' is 49.8MB. This size relatively large. As a result, Ray might excessively spill objects during execution. To fix this issue, avoid accessing `self` or other large objects in 'read_task_fn'.
```

When using a small number of blocks, OOM does not occur because the
large file list is not repeated so many times. But when setting high
parallelism with `override_num_blocks`, OOM occurs.

This is because the full list of paths is added to
`self._unresolved_paths`. This attribute isn't currently used anywhere
in ray. This PR removes `self._unresolved_paths` to alleviate unexpected
high memory usage with very large numbers of files.

## Related issue number

Similar to this issue with Iceberg: ray-project#49054

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [x] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [x] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Jack Gammack <[email protected]>
Signed-off-by: yenhong.wong <[email protected]>
alexwang177 pushed a commit to pinterest/ray that referenced this pull request Sep 17, 2025
…urce when using a large number of files (ray-project#55978)

## Why are these changes needed?

Using `FileBasedDatasource` or `ParquetDatasource` with a very large
number of files causes OOM when creating read tasks. The full list of
file paths is stored in `self`, causing it to persist to every read
task, leading to this warning:
```
The serialized size of your read function named 'read_task_fn' is 49.8MB. This size relatively large. As a result, Ray might excessively spill objects during execution. To fix this issue, avoid accessing `self` or other large objects in 'read_task_fn'.
```

When using a small number of blocks, OOM does not occur because the
large file list is not repeated so many times. But when setting high
parallelism with `override_num_blocks`, OOM occurs.

This is because the full list of paths is added to
`self._unresolved_paths`. This attribute isn't currently used anywhere
in ray. This PR removes `self._unresolved_paths` to alleviate unexpected
high memory usage with very large numbers of files.

## Related issue number

Similar to this issue with Iceberg: ray-project#49054 

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [x] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [x] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Jack Gammack <[email protected]>
dstrodtman pushed a commit to dstrodtman/ray that referenced this pull request Oct 6, 2025
…urce when using a large number of files (ray-project#55978)

## Why are these changes needed?

Using `FileBasedDatasource` or `ParquetDatasource` with a very large
number of files causes OOM when creating read tasks. The full list of
file paths is stored in `self`, causing it to persist to every read
task, leading to this warning:
```
The serialized size of your read function named 'read_task_fn' is 49.8MB. This size relatively large. As a result, Ray might excessively spill objects during execution. To fix this issue, avoid accessing `self` or other large objects in 'read_task_fn'.
```

When using a small number of blocks, OOM does not occur because the
large file list is not repeated so many times. But when setting high
parallelism with `override_num_blocks`, OOM occurs.

This is because the full list of paths is added to
`self._unresolved_paths`. This attribute isn't currently used anywhere
in ray. This PR removes `self._unresolved_paths` to alleviate unexpected
high memory usage with very large numbers of files.

## Related issue number

Similar to this issue with Iceberg: ray-project#49054

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [x] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [x] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Jack Gammack <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
…urce when using a large number of files (ray-project#55978)

## Why are these changes needed?

Using `FileBasedDatasource` or `ParquetDatasource` with a very large
number of files causes OOM when creating read tasks. The full list of
file paths is stored in `self`, causing it to persist to every read
task, leading to this warning:
```
The serialized size of your read function named 'read_task_fn' is 49.8MB. This size relatively large. As a result, Ray might excessively spill objects during execution. To fix this issue, avoid accessing `self` or other large objects in 'read_task_fn'.
```

When using a small number of blocks, OOM does not occur because the
large file list is not repeated so many times. But when setting high
parallelism with `override_num_blocks`, OOM occurs.

This is because the full list of paths is added to
`self._unresolved_paths`. This attribute isn't currently used anywhere
in ray. This PR removes `self._unresolved_paths` to alleviate unexpected
high memory usage with very large numbers of files.

## Related issue number

Similar to this issue with Iceberg: ray-project#49054 

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [x] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [x] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Jack Gammack <[email protected]>
richardliaw pushed a commit that referenced this pull request Aug 20, 2026
*I used CODEX to analyze this problem and create this PR. I've reviewed
the code and tests and stand by them. This summary is written completely
by a human (me) other than very light copy editing by an LLM.*

The problem I ran into was that with 50000 Iceberg read tasks the driver
was serializing 50000 copies of the same information as it serialized
the tasks into its object store. This PR replaces those copies with an
`ObjectRef` to the same information in Ray's distributed object store
and the workers fetch that data when needed.

This ended up being a meaningful performance gain in driver-side task
construction and serialization at scale, see the benchmarking section
below. In my production use case it reduced the Iceberg read-task
construction and serialization from over an hour to less than one
minute.


CODEX generated summary follows:
-----
Large Iceberg scans currently serialize the same PyIceberg scan state
into every Ray `ReadTask`. On a production-shaped scan with 50,000 read
tasks, that repeated metadata prevented Ray from finishing task
construction, delayed autoscaling indefinitely, and projected far beyond
the head node's object-store capacity.

This change stores the immutable scan state once in Ray's object store.
Each read task now carries only its file chunk and the shared
`ObjectRef`; the worker resolves that reference before calling the
existing Iceberg read implementation. Read semantics, planning,
projection, filtering, and delete handling are unchanged.

## Why this is not duplicate work

[#49054](#49054)
fixed
[#49107](#49107)
by removing the datasource's `self` reference from each read closure.
The replacement partial still captures table IO, full table metadata,
the row filter, and the projected schema in every task. Searches of open
PRs for that issue, `IcebergDatasource.get_read_tasks`, Iceberg
`ObjectRef`, `table_metadata`, serialized Iceberg reads, and Iceberg
object-store usage found no PR addressing that residual duplication.
[#61753](#61753)
touches this datasource for unrelated checkpoint filtering.

## Benchmark
A controlled single-node benchmark isolated the driver-side work changed
by this PR. It created a real local Iceberg table with 1,028 fields,
projected 290 fields, and replicated a planned FileScanTask to produce
different task counts. For each count, the benchmark constructed the
ReadTasks and stored each with ray.put, matching plan_read_op.py. Object
sizes were measured through get_local_object_locations.

The patched totals include both the serialized ReadTasks and the single
shared-state object.

| Read tasks | Base object-store bytes | Patched object-store bytes |
Reduction |
| ---: | ---: | ---: | ---: |
| 100 | 30.45 MB | 12.35 MB | 59.5% |
| 1,000 | 304.54 MB | 122.40 MB | 59.8% |
| 5,000 | 1.523 GB | 611.52 MB | 59.8% |

At 1,000 tasks, median task construction and serialization time across
three runs fell from 2.55 seconds to 0.46 seconds, a 5.5x improvement.

The local fixture’s shared state was 117 KB, substantially smaller than
the production workload’s metadata. It therefore demonstrates the
scaling behavior without reproducing the production-sized state.

On the production-shaped scan, the serialized size of one read task fell
from approximately 1.63 MiB to 106 KiB. The patched implementation
constructed all 50,000 tasks in 50.10 seconds, submitted the reads, and
allowed autoscaling to begin. The stock implementation did not finish
task construction or submit a read. Iceberg planning remained
approximately 100 seconds in both cases, as expected; this change
targets task serialization and construction rather than file planning.

## Tests

```text
.venv/bin/pytest -q python/ray/data/tests/datasource/test_iceberg.py --tb=short
# 55 passed

PATH="$PWD/.venv/bin:/opt/homebrew/bin:/usr/bin:/bin" bazel test //python/ray/data:test_iceberg \
  --test_output=errors --nocache_test_results --action_env=PATH \
  --test_env=VIRTUAL_ENV="$PWD/.venv"
# PASSED

pre-commit run --files \
  python/ray/data/_internal/datasource/iceberg_datasource.py \
  python/ray/data/tests/datasource/test_iceberg.py
# All applicable hooks passed
```

AI assistance was used to investigate the bottleneck, prototype the
change, implement the patch, and draft tests and this description. This
PR is a draft pending the human submitter's line-by-line review before
review is requested.

---------

Signed-off-by: Aaron Niskode-Dossett <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
*I used CODEX to analyze this problem and create this PR. I've reviewed
the code and tests and stand by them. This summary is written completely
by a human (me) other than very light copy editing by an LLM.*

The problem I ran into was that with 50000 Iceberg read tasks the driver
was serializing 50000 copies of the same information as it serialized
the tasks into its object store. This PR replaces those copies with an
`ObjectRef` to the same information in Ray's distributed object store
and the workers fetch that data when needed.

This ended up being a meaningful performance gain in driver-side task
construction and serialization at scale, see the benchmarking section
below. In my production use case it reduced the Iceberg read-task
construction and serialization from over an hour to less than one
minute.


CODEX generated summary follows:
-----
Large Iceberg scans currently serialize the same PyIceberg scan state
into every Ray `ReadTask`. On a production-shaped scan with 50,000 read
tasks, that repeated metadata prevented Ray from finishing task
construction, delayed autoscaling indefinitely, and projected far beyond
the head node's object-store capacity.

This change stores the immutable scan state once in Ray's object store.
Each read task now carries only its file chunk and the shared
`ObjectRef`; the worker resolves that reference before calling the
existing Iceberg read implementation. Read semantics, planning,
projection, filtering, and delete handling are unchanged.

## Why this is not duplicate work

[ray-project#49054](ray-project#49054)
fixed
[ray-project#49107](ray-project#49107)
by removing the datasource's `self` reference from each read closure.
The replacement partial still captures table IO, full table metadata,
the row filter, and the projected schema in every task. Searches of open
PRs for that issue, `IcebergDatasource.get_read_tasks`, Iceberg
`ObjectRef`, `table_metadata`, serialized Iceberg reads, and Iceberg
object-store usage found no PR addressing that residual duplication.
[ray-project#61753](ray-project#61753)
touches this datasource for unrelated checkpoint filtering.

## Benchmark
A controlled single-node benchmark isolated the driver-side work changed
by this PR. It created a real local Iceberg table with 1,028 fields,
projected 290 fields, and replicated a planned FileScanTask to produce
different task counts. For each count, the benchmark constructed the
ReadTasks and stored each with ray.put, matching plan_read_op.py. Object
sizes were measured through get_local_object_locations.

The patched totals include both the serialized ReadTasks and the single
shared-state object.

| Read tasks | Base object-store bytes | Patched object-store bytes |
Reduction |
| ---: | ---: | ---: | ---: |
| 100 | 30.45 MB | 12.35 MB | 59.5% |
| 1,000 | 304.54 MB | 122.40 MB | 59.8% |
| 5,000 | 1.523 GB | 611.52 MB | 59.8% |

At 1,000 tasks, median task construction and serialization time across
three runs fell from 2.55 seconds to 0.46 seconds, a 5.5x improvement.

The local fixture’s shared state was 117 KB, substantially smaller than
the production workload’s metadata. It therefore demonstrates the
scaling behavior without reproducing the production-sized state.

On the production-shaped scan, the serialized size of one read task fell
from approximately 1.63 MiB to 106 KiB. The patched implementation
constructed all 50,000 tasks in 50.10 seconds, submitted the reads, and
allowed autoscaling to begin. The stock implementation did not finish
task construction or submit a read. Iceberg planning remained
approximately 100 seconds in both cases, as expected; this change
targets task serialization and construction rather than file planning.

## Tests

```text
.venv/bin/pytest -q python/ray/data/tests/datasource/test_iceberg.py --tb=short
# 55 passed

PATH="$PWD/.venv/bin:/opt/homebrew/bin:/usr/bin:/bin" bazel test //python/ray/data:test_iceberg \
  --test_output=errors --nocache_test_results --action_env=PATH \
  --test_env=VIRTUAL_ENV="$PWD/.venv"
# PASSED

pre-commit run --files \
  python/ray/data/_internal/datasource/iceberg_datasource.py \
  python/ray/data/tests/datasource/test_iceberg.py
# All applicable hooks passed
```

AI assistance was used to investigate the bottleneck, prototype the
change, implement the patch, and draft tests and this description. This
PR is a draft pending the human submitter's line-by-line review before
review is requested.

---------

Signed-off-by: Aaron Niskode-Dossett <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-backlog go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants