Skip to content
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

lang: Zero copy deserialization #202

Merged
merged 23 commits into from
Apr 17, 2021
Merged

lang: Zero copy deserialization #202

merged 23 commits into from
Apr 17, 2021

Conversation

armaniferrante
Copy link
Member

@armaniferrante armaniferrante commented Apr 15, 2021

Addresses

Provides the ability to opt into zero copy deserialization for accounts. This means, instead of using borsh, accounts are defined with "plain old data" types that map 1-1 to the bytes in the backing AccountInfo's &mut [u8].

Other than being more efficient, the most salient benefit this provides is the ability to define account types larger than the max stack or heap size. This is used in special cases, for example, the Serum DEX event queue. When using borsh, one is limited, since the account has to be copied and deserialized into a new data structure. With zero copy deserialization, everything is, effectively, lazy loaded on field access.

To use this feature, one must define their account as

#[account(zero_copy)]
pub struct MyAccount {...}

Or for associated accounts

#[associated(zero_copy)]
pub struct MyAccount {...}

Otherwise, Borsh is still used, by default. The ts client will still work as expected in either case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant