-
Notifications
You must be signed in to change notification settings - Fork 500
RingBuffer contiguous memory optimization #187
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
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 addition of the check for capacity > 0 was to ensure we didn't cause a divide by zero when a zero size buffer was given (which often occurs in tests). Why were the test strings changed?
|
The test strings were changed to make the CI pass. I didn't encounter any division by zero errors. Should I try to solve my problem in a different way? |
|
If you're changing tests "to make CI green" that means it's equally likely that there was a bug in code or a bug in tests or a bug in specs but you didn't distinguish these cases. Which one is it?
…On April 10, 2018 10:17:36 PM GMT+08:00, Astro ***@***.***> wrote:
The test strings were changed to make the CI pass.
I didn't encounter any division by zero errors. Should I try to solve
my problem in a different way?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#187 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
|
I'm not 100% certain that this is the right approach. With the optimization, the buffer will be rewritten from start if it was empty after the previous |
|
It seems we have two separate things at work here:
@astro, can you please provide separate test cases for (1) and (2)? If the check is genuinely dead, then let's first remove it, and then separately examine the optimization (2); I don't fully understand why it is necessary yet. |
|
Ok, I reordered this PR with the updated tests first and had CI trigger on them. Now I've put the optimization into |
whitequark
left a comment
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 code change looks good to me but the change to the TCP test_buffer_wraparound_tx seems wrong.
src/socket/tcp.rs
Outdated
| assert_eq!(s.send_slice(b"abc"), Ok(3)); | ||
| s.tx_buffer = SocketBuffer::new(vec![b'.'; 9]); | ||
| assert_eq!(s.tx_buffer.enqueue_many(6).len(), 6); | ||
| assert_eq!(s.tx_buffer.dequeue_many(3).len(), 3); |
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.
Why are you manipulating the buffer directly in this test and not via the socket API? This defeats the purpose of testing the socket.
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.
Because this is just preparing the buffer. Anyway, fixed it.
… instead of comparing the buffer. Fixtures have been shortened to work with the outstanding contiguous buffer optimization.
This is still testing the same case which would be masked away by the upcoming contiguous space optimization (which is important for PacketBuffers and still helpful to TcpSockets).
| assert_eq!(s.send_slice(b"abc"), Ok(3)); | ||
| s.tx_buffer = SocketBuffer::new(vec![b'.'; 9]); | ||
| assert_eq!(s.send_slice(b"xxxyyy"), Ok(6)); | ||
| assert_eq!(s.tx_buffer.dequeue_many(3), &b"xxx"[..]); |
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.
This is not any better...
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.
Why touch the internal tx_buffer you ask? The read_at pointer must be initialized so that the check still makes sense when the optimization is merged.
|
@astro Thanks, and sorry for taking so much time to merge this. |
I've studied the code for a while and wondered why there is a check for
capacity > 0at this location.capacitydoesn't change. I believeself.lengthwas actually intended here.In the RawSocket use by #186 that's needed otherwise
PacketBuffertends to get a stuckpayload_ring(length=0butread_atnearcapacity).