Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VKT state migration optimized methods & lower LeafNode memory pressure #338

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

jsign
Copy link
Collaborator

@jsign jsign commented Apr 6, 2023

This PR contains the following:

  • A new conversion.go file with specifically crafted methods to support geth VKT state migration subcommand.
  • A change in value representation in LeafNodes optimized for the conversion case where spare 256 slices create a lot of memory pressure for the VKT conversion. This might be beneficial too for "daily" usage, but I doubt it might be entirely useful for that case.
  • Some nit changes using constant instead of magic numbers.

I preferred to do some heavy commenting in the code for future readers, but it will also serve as PR comments.

For context, see gballet/go-ethereum#196.

This PR is reviewable and mergable, but let's hold it open for a bit until we fully understand implications/results.

@jsign jsign marked this pull request as ready for review April 6, 2023 16:36
@jsign jsign changed the title VKT state migration optimized methods & less aggressive LeafNode memory pressure VKT state migration optimized methods & lower LeafNode memory pressure Apr 6, 2023
@jsign jsign requested a review from gballet April 10, 2023 16:46
go.mod Outdated Show resolved Hide resolved
Comment on lines -252 to +274
if i >= NodeWidth-1 {
if i >= NodeWidth {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to mention: I found this bug the hard way while doing the helpers and running stuff converting trees...

I think we got lucky to not see this bug happening before.

@jsign jsign force-pushed the jsign/newconversion branch from a32ba28 to 5126adb Compare April 13, 2023 16:48
Comment on lines +23 to +40
ret[i] = LeafNode{
values: nv.Values,
stem: nv.Stem,
c1: Generator(),
c2: Generator(),
}

var c1poly, c2poly [NodeWidth]Fr

valsslice := make([][]byte, NodeWidth)
for idx := range nv.Values {
valsslice[idx] = nv.Values[idx]
}

fillSuffixTreePoly(c1poly[:], valsslice[:NodeWidth/2])
ret[i].c1 = cfg.CommitToPoly(c1poly[:], 0)
fillSuffixTreePoly(c2poly[:], valsslice[NodeWidth/2:])
ret[i].c2 = cfg.CommitToPoly(c2poly[:], 0)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now that we merged the other emptyCode cached PR, we can exploit the same here. Maybe I can extract this code section to be shared between both.

For now, it won't make a big difference in the conversion since we're bottleneck by compactions.
I prefer to merge this PR as is with our correctness guarantees, and I'll do a PR right after with only that refactor.

Copy link
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

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

Looks good overall, but isn't using a map slowing things down, especially the serialization part?

@jsign
Copy link
Collaborator Author

jsign commented Apr 14, 2023

Looks good overall, but isn't using a map slowing things down, especially the serialization part?

This change was optimized for the tree conversion. In that case, we have a lot of memory pressure by having 256-slices where, most of the nodes, only use a few slots. The more efficient the RAM use, the more batching we can do.

For replay benchmark or "usual" run of block execution, that memory waste isn't that big since we don't have that many nodes in memory. In that case, using a map is paying some CPU cost for the cryptographic hash function maybe unnecessarily. I'd say is I change I'd ideally want to keep for the conversion code runs, and maybe not for master.

To mention some numbers, the map change allowed to save GiBs of ram in the tree conversion process.

jsign added 15 commits April 17, 2023 09:35
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
… tree building

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
@jsign
Copy link
Collaborator Author

jsign commented Apr 25, 2023

Marking this PR on-hold and switching to draft to avoid merging.

This PR is complete and works for a full tree conversion, but now we're also exploring the overlay tree conversion in parallel.
Until we figure out which strategy we'll use, we should hold a bit merging this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants