Skip to content

lang: Zero copy deserialization#202

Merged
armaniferrante merged 23 commits into
masterfrom
armani/zero
Apr 17, 2021
Merged

lang: Zero copy deserialization#202
armaniferrante merged 23 commits into
masterfrom
armani/zero

Conversation

@armaniferrante

@armaniferrante armaniferrante commented Apr 15, 2021

Copy link
Copy Markdown
Contributor

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.

Otter-0x4ka5h pushed a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
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.

1 participant