New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of VarZeroVec::deserialize and add provider benches #2603
Conversation
I included an extra commit, 508372c, with the following characteristics:
An extra 25% off the constructor at the cost of around 10% on the load function. It also saves a small amount of space in the postcard file. I am neutral on whether to include this additional change. |
provider/blob/src/blob_schema.rs
Outdated
pub indices: &'data FlexZeroSlice, | ||
/// Buffer slice | ||
#[serde(borrow)] | ||
pub buffer: &'data [u8], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I can probably get a further boost by using serde_bytes::Bytes or a similar type (likely an internal one) at this spot, so that we use the deserialize_bytes code path instead of deserialize_seq.
provider/blob/src/blob_schema.rs
Outdated
#[serde(borrow)] | ||
pub buffers: &'data VarZeroSlice<[u8], Index32>, | ||
pub indices: &'data FlexZeroSlice, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I could instead write this to have the exact same binary representation as the VarZeroSlice, which would allow us to make the change later and go back and forth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is interest, this could be UnvalidatedVarZeroVec
. It would support only one type, byte slices, and the indices would be lazily validated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the current model in this PR just fine
The additional change increases maintenance complexity for the blob schema. I'd rather keep complicated ULE stuff contained in the zerovec crate. What's the core of that change, using a |
provider/blob/src/blob_schema.rs
Outdated
#[serde(borrow)] | ||
pub buffers: &'data VarZeroSlice<[u8], Index32>, | ||
pub indices: &'data FlexZeroSlice, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the current model in this PR just fine
See my comment threads in the code. The core of 508372c is delaying the validation of the indices array; VZV requires that it be sorted, but it doesn't really need to be since we're not validating the byte slices; we just hand them off to Postcard to deal with. |
I dropped 508372c to get the uncontroversial change checked in, and I'll open another PR with the schema change to discuss further. |
Fixes #2600
After @zbraniecki noticed a performance issue with StaticDataProvider's constructor, I looked into the code with @Manishearth and found some low-hanging fruit to optimize. I managed to get a 63% improvement, as shown below with the new benches run across the second commit in this PR: