Skip to content

Conversation

@technicallyty
Copy link
Contributor

Description

Closes: #25474

updates iavlx to use absolute offsets in branch layout

@technicallyty technicallyty requested a review from aaronc October 21, 2025 05:52
@codecov
Copy link

codecov bot commented Oct 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.83%. Comparing base (a50376f) to head (8585d2b).
⚠️ Report is 3 commits behind head on aaronc/iavlx.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff                @@
##           aaronc/iavlx   #25482      +/-   ##
================================================
- Coverage         52.88%   52.83%   -0.05%     
================================================
  Files               797      798       +1     
  Lines             64903    64953      +50     
================================================
- Hits              34322    34317       -5     
- Misses            30581    30636      +55     

see 6 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

Yep this looks like the right direction. It shouldn't be too complex.

Comment on lines 15 to 23
SizeBranch = 88
)

type BranchLayout struct {
Id NodeID
Left NodeRef
Right NodeRef
Left NodeID
LeftOffset uint32 // absolute offset
Right NodeID
RightOffset uint32 // absolute offset
Copy link
Member

Choose a reason for hiding this comment

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

Ah so I can see how this snippet looks totally equivalent to what I posted on slack! But the order actually matters and affects the struct size. So when we place NodeID (8 bytes) next to a uint32 (4 bytes), the compiler actually makes it take up 16 bytes with 4 bytes of padding. And if we do this twice, we use 32 bytes of space. If we put the offsets together, there is no extra padding and the same data only uses 24 bytes. If you're not too familiar with struct alignment and padding, there a bunch of articles you can find by googling.

Suggested change
SizeBranch = 88
)
type BranchLayout struct {
Id NodeID
Left NodeRef
Right NodeRef
Left NodeID
LeftOffset uint32 // absolute offset
Right NodeID
RightOffset uint32 // absolute offset
SizeBranch = 80
)
type BranchLayout struct {
Id NodeID
Left NodeID
Right NodeID
LeftOffset uint32 // absolute offset
RightOffset uint32 // absolute offset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

branchesWriter: NewStructWriter[BranchLayout](newFiles.branchesFile),
versionsWriter: NewStructWriter[VersionInfo](newFiles.versionsFile),
keyCache: make(map[string]uint32),
leafOffsetRemappings: make(map[uint32]uint32),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
leafOffsetRemappings: make(map[uint32]uint32),

We no longer need this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 242 to 250
leftPtr := cr.resolveNodeID(layout.Left)
rightPtr := cr.resolveNodeID(layout.Right)

return &BranchPersisted{
layout: layout,
store: cr,
selfIdx: actualIdx,
leftPtr: leftPtr,
rightPtr: rightPtr,
Copy link
Member

Choose a reason for hiding this comment

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

We actually can delete the leftPtr, rightPtr and I think even selfIdx fields from BranchPersisted now. They're longer needed because BranchLayout now includes everything we need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the fields, and updated resolve to match new data

@technicallyty technicallyty marked this pull request as ready for review October 23, 2025 05:59
@technicallyty technicallyty requested a review from aaronc October 23, 2025 05:59
@github-actions
Copy link
Contributor

@technicallyty your pull request is missing a changelog!

defer cs.Unpin()

// get version data
version := uint32(nodeId.Version())
Copy link
Member

Choose a reason for hiding this comment

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

This should be at the top of the func, no need to call Version() twice

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.

3 participants