-
Notifications
You must be signed in to change notification settings - Fork 375
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
test: add reverseiterator tests #1058
Conversation
Thank you contribution! Which line of code will trigger underline array copying? the original Next() automatically validate the boundary during reslicing. new changes could leave the cur dangling out of the boundary. |
Hi,
I realize the term copying is probably not a great way to describe it. This is the line that made me work: https://github.com/gnolang/gno/pull/1058/files#diff-357b5cf1fe3b41c11ec07a21d11364079ac798c1b6d7817df02a2065f3e5a9b4L59 Also, this repeated 'if ascending` checks:
I don't think I follow exactly what you meant. But here's my view: About the cur pointing out of boundary: New logic's cur value will have either len() or -1 at the end of the iteration if this was what you meant by dangling out of the boundary, that's intended and such condition is used to check in Valid() method. Since the cur value is not exposed to users, I don't get to see what the concerns would be around that. About validation. Both logic relies on mi.assertValid() for validation. Original logic must do it otherwise real panic will happen on reslicing. It's an option for new logic but I left it there to keep it behaving the same. Personally, I'd prefer not to have Valid() method but only Next() if it's possible to refactor the behavior but that's out of this PR range. Thanks for the feedback. Let me know what you think @piux2 |
also @wolkykim if your interested in joining the team for our regular calls please let me know. |
@wolkykim thank you for the explanation, your testing case is good! please see my comments below and let me know what you think. The iterator functions as a memcache iterator, with the underlying data structure being a slice, []items, that contains pointers to the key-value pairs. When the Next() method is called, the length of the []items slice decreases (by executing mi.items = mi.items[1:]). Although the underlying array remains unaltered, any memory pointed by *std.KVPair that is stored outside the current length of the slice can become eligible for garbage collection by Go's memory management, assuming no secondary references to it exist elsewhere. This design is optimized for cache applications, ensuring that the iterator doesn't retain extra references to a *std.KVPair once it's been iterated over. Also, I do not see the expected performance improvement. I noticed -2.2% to -5.2% performance hit with the new implementation. I run 5 times for each comparison and received consistent outcome. here is the result of 1 of 5 comparisons existing implementation:
new implementation:
|
@piux2 Hi, yeah........ I see that the cursor approach didn't help the performance at all and actually made it slower. I ran the benchmark on my end and saw the same result. Also, see that your laptop has a faster CPU than mine. I'm surprised to learn that reslicing cost is that cheap. Thank you and I'm sorry for having your time spent on this. I have reverted the iterator change. This PR is now about adding the ReveseIterator test cases. Still lives 🤘 |
@wolkykim awesome! |
- update memiterator to use a cursor instead of reslicing in the iteration loop that also eliminates repeated if ascending check