h2 icon indicating copy to clipboard operation
h2 copied to clipboard

Improve write buffer strategy

Open carllerche opened this issue 6 years ago • 7 comments

Currently, the write buffer is not reused when it gets full.

Switching to a ring buffer would probably be better.

carllerche avatar Dec 19 '17 22:12 carllerche

@carllerche I am giving https://github.com/gnzlbg/slice_deque the finishing touches.

gnzlbg avatar Jan 13 '18 12:01 gnzlbg

Cool, anything we use would need to implement Buf and BufMut from the bytes crate though.

carllerche avatar Jan 18 '18 17:01 carllerche

Don't &[T] and &mut [T] implement that?


Edit: doesn't look like it. I can add it behind a feature flag.

gnzlbg avatar Jan 18 '18 18:01 gnzlbg

Also, looking more into this, it looks a bit more than we'd want to use. Having discontinuous slices is fine for our use case and I'd rather favor portability and use the built in allocator.

The project looks interesting though.

carllerche avatar Jan 18 '18 18:01 carllerche

How do you plan to implement bytes::Buf::bytes for VecDeque? It returns a slice but VecDeque can't do that.

gnzlbg avatar Jan 18 '18 18:01 gnzlbg

Buf::Bytes does not guarantee to return all remaining bytes. Once done w/ the slice returned by bytes, advance is called.

There is also a fn to get a batch of byte slices.

You are correct that the docs are not clear, I opened https://github.com/carllerche/bytes/issues/178 to track this.

carllerche avatar Jan 18 '18 18:01 carllerche

Makes sense :)


FWIW SliceDeque supports the bytes crate already :)

gnzlbg avatar Jan 18 '18 19:01 gnzlbg