Skip to content

Use compact primitive storage for star-tree record offsets in OffHeapSingleTreeBuilder - #19317

Open
Jackie-Jiang wants to merge 1 commit into
apache:masterfrom
Jackie-Jiang:compact_star_tree_record_offsets
Open

Use compact primitive storage for star-tree record offsets in OffHeapSingleTreeBuilder#19317
Jackie-Jiang wants to merge 1 commit into
apache:masterfrom
Jackie-Jiang:compact_star_tree_record_offsets

Conversation

@Jackie-Jiang

Copy link
Copy Markdown
Contributor

Summary

OffHeapSingleTreeBuilder keeps the star-tree record file offsets in a List<Long>, which costs ~28 bytes of heap per record (24-byte boxed Long plus a 4-byte reference under compressed oops). The number of star-tree records can go into the hundreds of millions for large segments with a wide dimensionsSplitOrder; in one production incident the offsets list alone held ~700M boxed Longs (~19.6GB including the ArrayList backing array), OOMing the server during realtime segment conversion.

This PR replaces the boxed list with a compact RecordOffsets structure:

  • Offsets are tracked as a prefix sum of the appended record lengths, so appendRecord passes the record length instead of computing the next offset from a read-back of the last element.
  • Start offsets are stored in an IntArrayList (4 bytes per record) until the record file grows beyond Integer.MAX_VALUE, and in a LongArrayList (8 bytes per record) afterwards. Offsets increase monotonically, so the switch happens at most once and needs no copy: reads pick the list by comparing the index against the int head's size.
  • The end offset (total file length) is a plain long field, removing the extra end-sentinel entry and the boxing/unboxing on every append and on every read in the star-node sort comparator.

For the build above this reduces the offset bookkeeping from ~19.6GB to ~5.6GB of heap (4 bytes per record while the record file stays under 2GB), and removes the Long allocation churn from the build hot path.

@Jackie-Jiang Jackie-Jiang added performance Related to performance optimization star-tree index Related to StarTree index labels Aug 19, 2026
@Jackie-Jiang
Jackie-Jiang requested a balanced review from Copilot August 19, 2026 19:47

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov-commenter

codecov-commenter commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.12%. Comparing base (11c3429) to head (bd52feb).

Files with missing lines Patch % Lines
.../startree/v2/builder/OffHeapSingleTreeBuilder.java 91.30% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #19317      +/-   ##
============================================
- Coverage     67.12%   67.12%   -0.01%     
  Complexity     1424     1424              
============================================
  Files          3462     3462              
  Lines        220669   220677       +8     
  Branches      35253    35255       +2     
============================================
- Hits         148129   148123       -6     
- Misses        60720    60722       +2     
- Partials      11820    11832      +12     
Flag Coverage Δ
integration 100.00% <ø> (ø)
integration1 100.00% <ø> (ø)
integration2 0.00% <ø> (ø)
java-25 67.12% <91.30%> (-0.01%) ⬇️
lane-a 100.00% <ø> (ø)
lane-b 0.00% <ø> (ø)
temurin 67.12% <91.30%> (-0.01%) ⬇️
unittests 67.11% <91.30%> (-0.01%) ⬇️
unittests1 57.79% <78.26%> (-0.04%) ⬇️
unittests2 39.13% <91.30%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Related to performance optimization star-tree index Related to StarTree index

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants