Core: Intern PartitionData during scan planning to avoid duplicate allocations

Open
#18,861 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #18862 by @wangyum — closed without merging

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
java, spark

Research direction

Start with PartitionData.copy() and copyFor(), then inspect BaseFile's copy constructor and the GuavaClasses relocation list. Check the existing tests for PartitionData.equals and hashCode, especially binary partition values. Done means equal partitions can share interned instances safely, binary values compare by content, and the relocated Guava classes retain the interner APIs; linked pull request #18862 is already open.

Written by the indexing model from the issue text.

Description

Feature Request / Improvement

Scan planning on large tables allocates one PartitionData (plus its backing Object[]) per manifest entry, even when millions of files share a small number of distinct partition values. On merge-on-read tables with many small files and many delete files (e.g. after heavy DV/position-delete churn without regular compaction), this produces millions of redundant PartitionData instances on the Spark driver during scan planning and contributes materially to Driver OOM.

Observed evidence (production heap dump, Spark driver)

Table scanned: ~4.4M data files + ~4.34M delete files, only a few thousand distinct physical partitions.

Class Instance count Retained
org.apache.iceberg.PartitionData 8,738,866 ~489 MB
java.lang.Object[] (backing arrays) 9,697,151 ~614 MB

PartitionData count == data files + delete files exactly: each manifest entry pays for a private copy, allocated via BaseFile's copy constructor:

// BaseFile (copy constructor)
this.partitionData = toCopy.partitionData.copy();

PartitionData.copy() / copyFor() unconditionally allocate a fresh instance and backing array; there is no deduplication across entries with identical partition values.

Query engine

Spark

Willingness to contribute
  • I can contribute this improvement/fix independently
Proposed approach

Route PartitionData.copy() / copyFor() through a weak Guava Interner so entries with equal partition spec and values collapse to a single shared instance. Weak keys ensure interned instances are evicted once nothing references them, so this is safe for long-lived processes planning scans across many tables.

Two supporting changes:

  1. PartitionData.equals/hashCode currently use Arrays.equals(Object[], Object[]) / Arrays.hashCode(Object[]), which compare elements by reference — partitions with BINARY/FIXED columns (stored as byte[]) never compare equal. Switch to Arrays.deepEquals / Arrays.deepHashCode so binary partition values intern correctly (this is independently a latent correctness bug for any Map/Set keyed on PartitionData with binary partition columns).
  2. Retain Interner/Interners in the minimized relocated bundled-guava jar (GuavaClasses), which currently strips them.

Related work on the same Driver-OOM theme: #18359 (reduces DeleteFileIndex memory for file-scoped position deletes/DVs). This improvement is complementary and addresses a different allocation source.

Dominant language
Java
Stars
9.5k
Forks
3.7k
Avg merge
2d 2h
Merged PRs (30d)
170

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/iceberg

All issues in apache/iceberg

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.