Requesting single bytes from a tcp/ip stack incurs significant overhead.
I made a quick change to buffer coercion in src/tds/codec/column_data/plp.rs and in my specific case, performance improved by a factor of 3 (in my case when utilizing varchar).
The changes I made were as follows:
in fn decode
(comment this for loop out)
//for _ in 0..len {
// data.push(src.read_u8().await?);
//}
(replace with this)
data.resize(len as usize, 0u8); // actually allocate the space
src.read(&mut data).await?; // bulk read the data
Last else loop of decode (my case did not test this, concept code only):
//let byte = src.read_u8().await?;
//chunk_data_left -= 1;
//data.push(byte);
let mut buffer=Vec::with_capacity(chunk_data_left); // create a temporary storage for block
buffer.resize(chunk_data_left,0u8); // actually allocate the space
src.read(&mut buffer).await?; // bulk read the data
data.extend_from_slice(&buffer);
chunk_data_left=0;
Requesting single bytes from a tcp/ip stack incurs significant overhead.
I made a quick change to buffer coercion in src/tds/codec/column_data/plp.rs and in my specific case, performance improved by a factor of 3 (in my case when utilizing varchar).
The changes I made were as follows:
in fn decode
(comment this for loop out)
//for _ in 0..len {
// data.push(src.read_u8().await?);
//}
(replace with this)
data.resize(len as usize, 0u8); // actually allocate the space
src.read(&mut data).await?; // bulk read the data
Last else loop of decode (my case did not test this, concept code only):
//let byte = src.read_u8().await?;
//chunk_data_left -= 1;
//data.push(byte);
let mut buffer=Vec::with_capacity(chunk_data_left); // create a temporary storage for block
buffer.resize(chunk_data_left,0u8); // actually allocate the space
src.read(&mut buffer).await?; // bulk read the data
data.extend_from_slice(&buffer);
chunk_data_left=0;