fix(codec): Allocate inbound buffer once (#578)
Gets rid of reallocs when receiving large messages, increasing throughput by about 30%-40%.
This commit is contained in:
@@ -180,6 +180,7 @@ impl<T> Streaming<T> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let len = self.buf.get_u32() as usize;
|
let len = self.buf.get_u32() as usize;
|
||||||
|
self.buf.reserve(len);
|
||||||
|
|
||||||
self.state = State::ReadBody {
|
self.state = State::ReadBody {
|
||||||
compression: is_compressed,
|
compression: is_compressed,
|
||||||
@@ -235,16 +236,6 @@ impl<T> Stream for Streaming<T> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(data) = chunk {
|
if let Some(data) = chunk {
|
||||||
if data.remaining() > self.buf.remaining_mut() {
|
|
||||||
let amt = if data.remaining() > BUFFER_SIZE {
|
|
||||||
data.remaining()
|
|
||||||
} else {
|
|
||||||
BUFFER_SIZE
|
|
||||||
};
|
|
||||||
|
|
||||||
self.buf.reserve(amt);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.buf.put(data);
|
self.buf.put(data);
|
||||||
} else {
|
} else {
|
||||||
// FIXME: improve buf usage.
|
// FIXME: improve buf usage.
|
||||||
|
|||||||
Reference in New Issue
Block a user