Skip to content

[x/programs] Pass arguments as one serialized tuple #638

Closed
@samliok

Description

@samliok

As @richardpringle and I discussed offline, it may be more effective to serialize all arguments in one tuple instead of serializing each argument individually.

Currently, when calling #[public] functions from the host or with call_program we do the following

  • we serialize every individual parameter using borsh and then prepending it with the length of its bytes.
  • deserialize each individual parameter in rust by grabbing the byte length and then calling borsh

By serializing all arguments into a singular tuple(which borsh supports), we can reduce serialization and a good amount of memory allocations. Take the transfer function for example
pub fn transfer(program: Program, sender: Address, recipient: Address, amount: i64) -> bool

Currently we must serialize and then deserialize every argument we want to pass in. Instead on the host side we could create a tuple like (program, sender, recipient, amount) and then perform only one serialization as described above. On the receiving end, we adjust the #[public] proc macro to do the following

  • deserialization the entire tuple at once
  • split the tuple up and sequentially pass the arguments to the desired function

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

  • Status

    Done ✅

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions