Skip to content

Commit 3dcf989

Browse files
committed
postgres-replication: reuse underlying allocation for tuple data
The logical replication parsing routine for tuple data left some performance on the table by copying the replication data into new allocations instead of reusing the ones provided by the underlying `Bytes` buffer. Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
1 parent 7d2f14e commit 3dcf989

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

postgres-replication/src/protocol.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,8 @@ impl TupleData {
442442
TUPLE_DATA_TOAST_TAG => TupleData::UnchangedToast,
443443
TUPLE_DATA_TEXT_TAG => {
444444
let len = buf.read_i32::<BigEndian>()?;
445-
let mut data = vec![0; len as usize];
446-
buf.read_exact(&mut data)?;
447-
TupleData::Text(data.into())
445+
let data = buf.read_buf(len as usize)?;
446+
TupleData::Text(data)
448447
}
449448
TUPLE_DATA_BINARY_TAG => {
450449
let len = buf.read_i32::<BigEndian>()?;
@@ -778,6 +777,20 @@ impl Buffer {
778777
self.idx = self.bytes.len();
779778
buf
780779
}
780+
781+
#[inline]
782+
fn read_buf(&mut self, len: usize) -> io::Result<Bytes> {
783+
if self.idx + len <= self.bytes.len() {
784+
let buf = self.bytes.slice(self.idx..(self.idx + len));
785+
self.idx += len;
786+
Ok(buf)
787+
} else {
788+
Err(io::Error::new(
789+
io::ErrorKind::UnexpectedEof,
790+
"unexpected EOF",
791+
))
792+
}
793+
}
781794
}
782795

783796
impl Read for Buffer {

0 commit comments

Comments
 (0)