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

eth/downloader: dereference discarded statesync request #15545

Merged
merged 1 commit into from
Jan 2, 2018

Conversation

karalabe
Copy link
Member

In the state synchronization structure of the downloader we are maintaining a finished slice containing all the currently pending responses (or timeouts) to state requests. Whenever the state processor accepts a pending item, we shift the entire slice to the left.

However, since finished is backed by a single array internally, reducing the length by one will still keep the last item in a live (alas currently unreachable) array, and as such will keep a live memory reference to it. This in theory shouldn't matter much as it will soon enough be overwritten, but given our memory problems during sync, I'd rather avoid any such dangling GC references.

@karalabe karalabe requested a review from fjl November 23, 2017 12:35
@karalabe karalabe added this to the 1.8.0 milestone Nov 23, 2017
// Shift out the first request, but also set the emptied slot to nil for GC
copy(finished, finished[1:])
finished[len(finished)-1] = nil
finished = finished[:len(finished)-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

You can get the same effect using

finished = append(finished[:0:len(finished)-1], finished[1:]...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, this full format seems to reduce the capacity too, meaning it would be a reallocation of the underlying buffer. Am I missing something?

Copy link
Contributor

@fjl fjl Dec 21, 2017

Choose a reason for hiding this comment

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

I suggested this because I thought you want to avoid growing the slice indefinitely. The threeway slice expression does this.

If all you want is setting the unused element to nil, your solution is OK.

It's hard to decide, I want to keep the code compact. This operation isn't worth three lines + comment.

@fjl fjl merged commit 9c42a41 into ethereum:master Jan 2, 2018
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.

None yet

2 participants