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

[Merged by Bors] - Pre-allocate vectors in SSZ decoding #3417

Closed

Conversation

michaelsproul
Copy link
Member

Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The size_hint is derived from the range iterator here:

(1..=num_items).map(|i| {

Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.

@michaelsproul michaelsproul added work-in-progress PR is a work-in-progress low-hanging-fruit Easy to resolve, get it before someone else does! optimization Something to make Lighthouse run more efficiently. labels Aug 3, 2022
@michaelsproul
Copy link
Member Author

michaelsproul commented Aug 10, 2022

Running this for 24h on two similar Ropsten nodes didn't yield any significant change. If anything the vanilla v2.5.1 (light blue) code seems to be using slightly less free memory than this PR (dark blue)

total_memory

free_memory

I'm on the fence about whether we should bother merging it. On one hand explicit is better than implicit, so maybe we should be explicit about the allocation behaviour we want here rather than relying on the optimiser or the allocator to smooth it out for us (i.e. merge). On the other hand, if it ain't broke maybe we shouldn't meddle with it unnecessarily.

@michaelsproul michaelsproul added ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels Aug 10, 2022
@realbigsean realbigsean added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Sep 13, 2022
@michaelsproul michaelsproul added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Sep 14, 2022
@realbigsean realbigsean added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Sep 15, 2022
@paulhauner
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Sep 16, 2022
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
@bors
Copy link

bors bot commented Sep 16, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Sep 16, 2022
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
@bors
Copy link

bors bot commented Sep 16, 2022

This PR was included in a batch that was canceled, it will be automatically retried

@paulhauner
Copy link
Member

bors r-

@bors
Copy link

bors bot commented Sep 16, 2022

Canceled.

@paulhauner
Copy link
Member

bors r+

@paulhauner
Copy link
Member

bors r-

@bors
Copy link

bors bot commented Sep 16, 2022

Canceled.

@paulhauner
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Sep 16, 2022
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
@bors
Copy link

bors bot commented Sep 16, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Sep 16, 2022
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
@bors
Copy link

bors bot commented Sep 16, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Sep 16, 2022
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
@bors bors bot changed the title Pre-allocate vectors in SSZ decoding [Merged by Bors] - Pre-allocate vectors in SSZ decoding Sep 16, 2022
@bors bors bot closed this Sep 16, 2022
@michaelsproul michaelsproul deleted the pre-allocate-ssz-decode branch September 16, 2022 18:43
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: sigp#3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low-hanging-fruit Easy to resolve, get it before someone else does! optimization Something to make Lighthouse run more efficiently. ready-for-merge This PR is ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants