Skip to content

Add RAMInt1SegmentDataAccess#3323

Open
easbar wants to merge 3 commits intomasterfrom
ramint1segment
Open

Add RAMInt1SegmentDataAccess#3323
easbar wants to merge 3 commits intomasterfrom
ramint1segment

Conversation

@easbar
Copy link
Copy Markdown
Member

@easbar easbar commented Mar 25, 2026

It's like RAMIntDataAccess, but it is backed by int[], rather than int[][]. So it does not offer cheap resizing and is limited to 2B ints, but the reading speed can be slightly faster, since we do not need the outer index access.

Even though there are no real segments the implementation still uses the segment size:

  • to keep file compatibility with the other DataAccess implementations (ensureCapacity and trimTo make sure the array length is a multiple of the segment size)
  • to fit into the DataAccessTest hierarchy
  • as buffer size in loadExisting() and flush(), just like RAMIntDataAccess

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new in-memory DataAccess implementation optimized for faster integer reads by using a single contiguous int[] instead of segmented int[][], and wires it into the directory/type system.

Changes:

  • Added RAMInt1SegmentDataAccess (single int[]-backed, int-only, optional storing via flush/loadExisting).
  • Extended DAType with _1SEG variants and a singleSegment flag, and updated GHDirectory to instantiate the new implementation.
  • Added RAMInt1SegmentDataAccessTest to integrate with the existing DataAccessTest hierarchy.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
core/src/main/java/com/graphhopper/storage/RAMInt1SegmentDataAccess.java New int[]-backed DataAccess implementation incl. load/flush and capacity management.
core/src/main/java/com/graphhopper/storage/GHDirectory.java Creates RAMInt1SegmentDataAccess when DAType is int-based and single-segment.
core/src/main/java/com/graphhopper/storage/DAType.java Adds _1SEG DA types and singleSegment flag influencing equality/toString.
core/src/test/java/com/graphhopper/storage/RAMInt1SegmentDataAccessTest.java Adds test class integration (currently overrides some base tests).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/src/main/java/com/graphhopper/storage/DAType.java Outdated
Comment on lines +46 to +55
/**
* Like RAM_INT, but backed by a single contiguous int[] for maximum read speed.
* Not a good fit if the array needs to be resized frequently. Limited to Integer.MAX_VALUE ints
* No support for short,byte and bytes.
*/
public static final DAType RAM_INT_1SEG = new DAType(MemRef.HEAP, false, true, true, true);
/**
* See RAM_INT_1SEG
*/
public static final DAType RAM_INT_1SEG_STORE = new DAType(MemRef.HEAP, true, true, true, true);
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.

will have to refactor this into an enum. but will do this after we merge this here.

Comment on lines +222 to +225
@Override
public int getSegments() {
return data.length / (segmentSizeInBytes / 4);
}
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.

this is a bit inconsistent as I would have expected 1 here (hence the 1Segment name). But we can keep it as it is to be more compatible with the other DataAccess classes

Copy link
Copy Markdown
Member

@karussell karussell left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants