Skip to content

fix(core): avoid sparse-ID shortest-path memory amplification - #3468

Open
contrueCT wants to merge 1 commit into
apache:masterfrom
contrueCT:task/asf-3466-shortest-memory
Open

contrueCT wants to merge 1 commit into
apache:masterfrom
contrueCT:task/asf-3466-shortest-memory

Conversation

@contrueCT

@contrueCT contrueCT commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Purpose of the PR

Shortest-path traversal encoded string IDs through sparse integer keys and used fixed-address segmented records. A small number of widely separated keys could allocate large arrays before the traversal had visited many vertices, causing OutOfMemoryError: Java heap space.

Main Changes

The shortest-path record implementation now uses the existing hash-backed RecordType.ARRAY representation and an Eclipse Collections integer hash set for visited vertices. Path reconstruction reads parent iterators through the Record interface, so it no longer depends on Int2IntRecord.

The same three sparse keys occupy three fixed-address segments above and one compact hash table below

The change is local to ShortestPathRecords; it does not alter the global collection factory or other traversal algorithms.

The regression coverage includes sparse string IDs, unreachable paths, mixed sparse numeric/string IDs, hash collisions, unlimited request parameters, multiple shortest paths, and a 1,000-key sparse layer.

Verifying these changes

  • Need tests and can be verified as follows:
    • JDK 17, -Xmx256m, ActiveProcessorCount=2.
    • mvn test -pl hugegraph-server/hugegraph-test -am -P unit-test -Dtest=ShortestPathTraverserTest -Dsurefire.failIfNoSpecifiedTests=false.
    • 20 tests passed with 0 failures and 0 skips.
    • The same sparse-layer probe OOMs on the unmodified implementation in IntMapByFixedAddr and completes with this change.

The validation is local and does not establish HStore production throughput or full end-to-end acceptance.

Does this PR potentially affect the following parts?

  • Dependencies
  • Modify configurations
  • The public API
  • Other affects
  • Nope

Documentation Status

  • Doc - No Need

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.63%. Comparing base (f60b628) to head (8485bf4).

Additional details and impacted files
@@            Coverage Diff             @@
##             master    #3468    +/-   ##
==========================================
  Coverage     58.63%   58.63%            
- Complexity     6933     7310   +377     
==========================================
  Files           780      780            
  Lines         69635    69635            
  Branches       9605     9605            
==========================================
+ Hits          40829    40832     +3     
- Misses        25115    25117     +2     
+ Partials       3691     3686     -5     
Flag Coverage Δ *Carryforward flag
commons 96.37% <ø> (ø) Carriedforward from f60b628
hstore 36.14% <ø> (-0.01%) ⬇️ Carriedforward from f60b628
pd 57.01% <ø> (ø) Carriedforward from f60b628
server_hbase 42.41% <ø> (-0.01%) ⬇️ Carriedforward from f60b628
server_memory 57.09% <100.00%> (+0.03%) ⬆️
server_rocksdb 42.90% <100.00%> (+<0.01%) ⬆️
store 36.17% <ø> (ø) Carriedforward from f60b628

*This pull request uses carry forward flags. 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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Blocking: no. Summary: The switch to RecordType.ARRAY and IntHashSet removes the sparse-key fixed-address allocation in ShortestPathRecords without changing path reconstruction, and the new tests ran green in UnitTestSuite. One cleanup: the PR commits its description diagram into the repository.

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

Score: 8.2/10 · Confidence: medium

Blocking: no

Summary

The hash-backed record change avoids sparse-key allocation while preserving single-parent path reconstruction. No new actionable correctness finding was identified. Approval is deferred because CI has failures and dense-graph performance remains unmeasured.

Evidence

Reviewed ID encoding, traversal and parent lookup against the record implementations; the PR adds sparse and collision cases. Server memory and RocksDB checks passed; commons, PD, Store and dependency checks failed.

Validation notes

Static independent review only; no independent runtime or production HStore performance test.

@contrueCT
contrueCT force-pushed the task/asf-3466-shortest-memory branch from 11264fb to 8485bf4 Compare November 26, 2026 12:57
@imbajin
imbajin requested an adaptive review from Copilot November 26, 2026 17:04

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.

🟢 Approval recommended

No active review issues are reported for the localized shortest-path storage change.

No open issues 🎉

What changed in this PR

Addresses #3466 by replacing sparse-ID-sensitive storage in shortest-path records with hash-backed collections, avoiding large fixed-address allocations while keeping the change local to shortest-path traversal.

Changes:

  • Uses RecordType.ARRAY for path records and IntHashSet for visited vertices.
  • Reconstructs paths through the Record interface rather than Int2IntRecord.
  • Adds regression coverage for sparse and mixed IDs, collisions, unreachable paths, unlimited parameters, multiple shortest paths, and a 1,000-key layer.
File Description
hugegraph-server/​hugegraph-test/​src/​main/​java/​org/​apache/​hugegraph/​unit/​traversal/​ShortestPathTraverserTest.java Adds sparse-ID memory-growth and shortest-path correctness regression tests.
hugegraph-server/​hugegraph-core/​src/​main/​java/​org/​apache/​hugegraph/​traversal/​algorithm/​records/​ShortestPathRecords.java Switches to hash-backed storage and interface-based parent lookup.

Review effort: Balanced (adaptive)

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

Score: 8.2/10 · Confidence: medium

Blocking: no

Summary

The hash-backed records avoid fixed-address allocation for sparse IDs and preserve single-parent path reconstruction. No new actionable correctness issue was established. Dense layers may use substantially more memory, so representative heap and throughput measurements would be useful.

Evidence

Int2IntsMap allocates ten int slots per distinct key plus a hash map; isNew admits one parent per layer. The existing SVG comment is resolved by its removal from the diff. The current Server memory and RocksDB CI jobs passed.

Validation notes

Independent review was static; no heap comparison, production HStore test, or independent test execution was performed. Actual dense-workload impact depends on occupancy and allocation overhead.

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

Blocking: no. Summary: Hash-backed records remove the fixed-address segment allocation for sparse codes, path reconstruction still follows the single parent isNew() admits, and the new tests ran green in UnitTestSuite. One cost remains: RecordType.ARRAY spends several times more heap per key than a one-value map on large dense numeric layers.

super(RecordType.INT, false, sourceV, targetV);
// ID hash codes are sparse; fixed-address records allocate large arrays
// for a handful of vertices. Reuse the hash-backed path records instead.
super(RecordType.ARRAY, false, sourceV, targetV);

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.

Minor: RecordType.ARRAY stores each layer in Int2IntsMap, which reserves a 10-int chunk per key although isNew() admits one parent per key, so a layer of 5M dense numeric ids retains about 460 MB against about 137 MB in an IntIntHashMap. Back these records with a one-parent-per-key IntIntHashMap record instead.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid sparse-ID memory amplification in shortest-path records

4 participants