-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Avoid temporary Vecs when serialising objects with discriminators #2691
Conversation
@mina86 is attempting to deploy a commit to the coral-xyz Team on Vercel. A member of the Team first needs to authorize it. |
I’m now getting failure in
|
That's strange but I'm assuming that's only locally since
CI logs: https://github.com/coral-xyz/anchor/actions/runs/6705905390/job/18221452799?pr=2691#step:10:610 |
All green. |
When serialising objects prefixed by a discriminator, rather then using BorshSerialize::try_to_vec to create a temporary vector that is appended to the output vector, create the output in advance, add discriminator to it and then use BorshSerialize::serialize to serialise the object directly to it. Issue: coral-xyz#2231
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 agree that it makes sense to set the default allocation to 256 instead of 1024 for most programs.
Overall, the changes look good to me but I'd like to play with it locally before merging.
let mut data = anchor_lang::idl::IDL_IX_TAG.to_le_bytes().to_vec(); | ||
data.append(&mut ix_inner.try_to_vec()?); | ||
let mut data = Vec::with_capacity(256); | ||
data.extend_from_slice(&anchor_lang::idl::IDL_IX_TAG.to_le_bytes()); | ||
ix_inner.serialize(&mut data)?; |
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.
We serialize 1000 bytes per each IDL Write
instruction(most IDLs are bigger):
Line 2397 in 4c0af6d
const MAX_WRITE_SIZE: usize = 1000; |
CLI and client changes are negligible but I'm onboard with including them for the sake of consistency.
Yep, this is much better. Could you note this change in the CHANGELOG? |
Done. |
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.
Thank you!
When serialising objects prefixed by a discriminator, rather then
using BorshSerialize::try_to_vec to create a temporary vector that is
appended to the output vector, create the output in advance, add
discriminator to it and then use BorshSerialize::serialize to
serialise the object directly to it.
Issue: #2231