Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Improved read avro performance (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Jun 29, 2022
1 parent 9c6b74a commit 38ecbb4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/io/avro/read/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fn read_block<R: Read>(
};

block.data.clear();
block.data.resize(bytes, 0);
reader.read_exact(&mut block.data)?;
block.data.try_reserve(bytes)?;
reader.take(bytes as u64).read_to_end(&mut block.data)?;

let mut marker = [0u8; 16];
reader.read_exact(&mut marker)?;
Expand Down
5 changes: 3 additions & 2 deletions src/io/avro/read/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ fn decode_variable<R: Read>(reader: &mut R) -> Result<u64> {

fn _read_binary<R: Read>(reader: &mut R) -> Result<Vec<u8>> {
let len: usize = zigzag_i64(reader)? as usize;
let mut buf = vec![0u8; len];
reader.read_exact(&mut buf)?;
let mut buf = vec![];
buf.try_reserve(len)?;
reader.take(len as u64).read_to_end(&mut buf)?;
Ok(buf)
}

Expand Down
7 changes: 5 additions & 2 deletions src/io/avro/read_async/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ async fn read_block<R: AsyncRead + Unpin + Send>(
};

block.data.clear();
block.data.resize(bytes, 0);
reader.read_exact(&mut block.data).await?;
block.data.try_reserve(bytes)?;
reader
.take(bytes as u64)
.read_to_end(&mut block.data)
.await?;

let mut marker = [0u8; 16];
reader.read_exact(&mut marker).await?;
Expand Down
5 changes: 3 additions & 2 deletions src/io/avro/read_async/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ async fn read_file_marker<R: AsyncRead + Unpin + Send>(reader: &mut R) -> Result

async fn _read_binary<R: AsyncRead + Unpin + Send>(reader: &mut R) -> Result<Vec<u8>> {
let len: usize = zigzag_i64(reader).await? as usize;
let mut buf = vec![0u8; len];
reader.read_exact(&mut buf).await?;
let mut buf = vec![];
buf.try_reserve(len)?;
reader.take(len as u64).read_to_end(&mut buf).await?;
Ok(buf)
}

Expand Down

0 comments on commit 38ecbb4

Please sign in to comment.