eth/downloader: dereference discarded statesync request#15545
Merged
Conversation
fjl
requested changes
Nov 27, 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] |
Contributor
There was a problem hiding this comment.
You can get the same effect using
finished = append(finished[:0:len(finished)-1], finished[1:]...)
Member
Author
There was a problem hiding this comment.
Actually, this full format seems to reduce the capacity too, meaning it would be a reallocation of the underlying buffer. Am I missing something?
Contributor
There was a problem hiding this comment.
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
approved these changes
Jan 2, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the state synchronization structure of the downloader we are maintaining a
finishedslice 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
finishedis 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.