-
Notifications
You must be signed in to change notification settings - Fork 20k
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
core/txpool/legacypool: remove a redundant heap.Init #28910
Conversation
This looks incorrect to me, but I'm slightly unsure. !h.Less(j, i) for 0 <= i < h.Len() and 2*i+1 <= j <= 2*i+2 and j < h.Len() The actual storage of a heap slice is NOT simply a sorted slice, it's a binary tree. So I think we can't just use the sorted slice as the heap. |
Thanks for the discussion. I will demonstrate that a sorted slice satisfies the invariance of a min-heap, which can be expressed as:
This invariant means that for any valid index In a stored slice:
This directly implies the heap invariance because if you pick any index also some similar discussions here: https://stackoverflow.com/questions/3113165/is-a-sorted-array-a-min-heap-whats-the-minimum-value-of-a-max-heap |
I agree, have seen this before. A sorted slice is a subset of a heap. A heap is just slightly more free, whereas the sorted slice is strict.
|
I agree that the change seems correct, but otoh:
So I'm kind of leaning towards letting it be as it is... (?) |
Agree with point 2, adding a btw, I added a benchmark test, removing before removing:
after removing:
Thus if the benefit is not obvious, can close this PR. |
I think it will have a larger effect if the transactions list is much longer, as it usually is for real world use cases. |
Make sense, some logs about the exact time inside Cap():
The |
So if I read it correctly, sorting is |
|
…eap" This reverts commit e8b23da.
Yeah, I think it's because the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: Martin HS <martin@swende.se>
Faster after changing the sorting function (from
|
I'm merging this because we're now running into the test timeout that has been plagueing the CI builder recently. The change itself is OK now. |
Co-authored-by: Martin HS <martin@swende.se> Co-authored-by: Felix Lange <fjl@twurst.com>
Found a redundant
heap.Init(m.index)
when learning the implementation of tx pool. this would saveO(threshold)
in eachCap()
call.Because
*m.index
is sorted increasingly and truncated the largestsize - threshold
values (same asm.Pop()
forsize - threshold
times), or addingheap.Init(m.index)
for completeness sake?