-
Notifications
You must be signed in to change notification settings - Fork 11
fix bug in meter traversal logic #11
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
Conversation
if m != nil { | ||
sw.meters[newLen] = m | ||
newLen++ | ||
} |
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.
There's actually a trick to this:
newMeters := sw.meters[:0]
for _, m := range sw.meters {
if m != nil {
newMeters = append(newMeters, m)
}
}
sw.meters = newMeters
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.
neat, but it probably generates the same code underneath :)
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.
do you want me to apply it? I am neutral either way and I usually prefer explicitness.
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.
actually, the trick might generate slower code because it has to do bounds checking.
Maybe the compiler is smart enough to elide it though, I wouldn't bet against it.
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.
The trick will do less bounds checking, IIRC. But I'm fine with this as it is.
@vyzo could you write a test for this? We can probably do this by:
The total for that last meter should see a massive spike. |
well, not with the fix! But we can haz a test. |
This is harder to trigger than it looks; we need to be actively putting stuff while the sweeper is running |
I managed to trigger it -- I made a small test that fails consistently before this patch, and passes after the patch. |
@vyzo @Stebalien this does appear to fix the issue on our end. At the very least the issue is a lot less frequent. We're going to deploy this to all of our nodes and then keep an eye on things for a few days to know for sure. |
See libp2p/go-libp2p-core#65