Skip to content

Commit

Permalink
solitaire: shrink stack footprint by boxing FromAccounts::from()
Browse files Browse the repository at this point in the history
  • Loading branch information
Stan Drozd authored and kcsongor committed Aug 17, 2022
1 parent 5db83ea commit 2092484
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion solana/solitaire/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl CreationLamports {
/// Trait definition that describes types that can be constructed from a list of solana account
/// references. A list of dependent accounts is produced as a side effect of the parsing stage.
pub trait FromAccounts<'a, 'b: 'a> {
fn from<T>(_: &'a Pubkey, _: &mut Iter<'a, AccountInfo<'b>>, _: &'a T) -> Result<Self>
fn from<T>(_: &'a Pubkey, _: &mut Iter<'a, AccountInfo<'b>>, _: &'a T) -> Result<Box<Self>>
where
Self: Sized;
}
2 changes: 1 addition & 1 deletion solana/solitaire/program/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ macro_rules! solitaire {
let ix_data = BorshDeserialize::try_from_slice(d).map_err(|e| SolitaireError::InstructionDeserializeFailed(e))?;
let mut accounts = FromAccounts::from(p, &mut a.iter(), &())?;
$fn(&ExecutionContext{program_id: p, accounts: a}, &mut accounts, ix_data)?;
Persist::persist(&accounts, p)?;
Persist::persist(accounts.as_ref(), p)?;
Ok(())
}
}
Expand Down
6 changes: 4 additions & 2 deletions solana/solitaire/rocksalt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn derive_from_accounts(input: TokenStream) -> TokenStream {
let expanded = quote! {
/// Macro generated implementation of FromAccounts by Solitaire.
impl #combined_impl_g solitaire::FromAccounts #peel_type_g for #name #type_g {
fn from<DataType>(pid: &'a solana_program::pubkey::Pubkey, iter: &mut std::slice::Iter<'a, solana_program::account_info::AccountInfo<'b>>, data: &'a DataType) -> solitaire::Result<Self> {
fn from<DataType>(pid: &'a solana_program::pubkey::Pubkey, iter: &mut std::slice::Iter<'a, solana_program::account_info::AccountInfo<'b>>, data: &'a DataType) -> solitaire::Result<Box<Self>> {
#from_method
}
}
Expand Down Expand Up @@ -108,7 +108,9 @@ fn generate_fields(name: &syn::Ident, data: &Data) -> TokenStream2 {
use solitaire::trace;
trace!("Peeling:");
#(#recurse;)*
Ok(#name { #(#names,)* })
// Necessary evil; Helps respect the 4K max
// stack frame size of the BPF VM
Ok(Box::new(#name { #(#names,)* }))
}
}

Expand Down

0 comments on commit 2092484

Please sign in to comment.