Skip to content

Performance improvement - handling buffers in plp.rs #226

@JasonCookSyncadd

Description

@JasonCookSyncadd

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions