-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into publish-idl
- Loading branch information
Showing
98 changed files
with
95,574 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
**/target | ||
**/Cargo.lock | ||
/.idea/ | ||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
[workspace] | ||
members=[ | ||
members = [ | ||
"shank", | ||
"shank-cli", | ||
"shank-idl", | ||
"shank-macro", | ||
"shank-macro-impl" | ||
] | ||
exclude=[ | ||
"./shank-idl/tests/fixtures/" | ||
"shank-macro-impl", | ||
"shank-render", | ||
] | ||
exclude = ["./shank-idl/tests/fixtures/"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Shank PDA/Seeds impl Overhead | ||
|
||
Measuring effects on `.so` artifact caused by `impl` functions generated by _shank_ to derive | ||
_seeds_ and _PDA_s. | ||
|
||
## Seeds/PDA Function Effects | ||
|
||
This diagnosis was performed on the [tictactoe workshop](https://github.com/thlorenz/tictactoe) | ||
which was hand rolling pda + seeds derivation. | ||
|
||
TODO: add a link to the relevant PR in tictactoe that changed that. | ||
|
||
According to this analysis the following was shown: | ||
|
||
- adding `impl` methods that aren't used in the code **does not add to the size of the `.so`** | ||
artifact | ||
- only when `impl` methods are invoked are they included in the binary and add to its size | ||
- due to _shank's_ efficient function reuse invoking its generated methods instead of the | ||
hand-rolled versions resulted in a smaller `.so` size (at least in this example) | ||
- final size ends up being smaller since _shank_ reuses the seed array creation code, vs. the | ||
hand rolled implementation inlined that code in two places. | ||
|
||
### Details | ||
|
||
For the following seeds specification: | ||
|
||
```rs | ||
#[derive(Debug, BorshSerialize, BorshDeserialize, ShankAccount)] | ||
#[seeds("tictactoe", game("The key of the game"))] | ||
pub struct Game { | ||
pub player_x: Pubkey, | ||
// [ .. ] | ||
} | ||
``` | ||
|
||
_shank_ generates the following code: | ||
|
||
```rs | ||
impl Game { | ||
/// Derives the seeds for this account. | ||
/// | ||
/// * **game**: The key of the game | [Pubkey] | ||
#[allow(unused, clippy::needless_lifetimes)] | ||
pub fn shank_seeds<'a>( | ||
game: &'a ::solana_program::pubkey::Pubkey, | ||
) -> [&'a [u8]; 2usize] { | ||
[b"tictactoe", game.as_ref()] | ||
} | ||
/// Derives the seeds for this account allowing to provide a bump seed. | ||
/// | ||
/// * **game**: The key of the game | [Pubkey] | ||
/// * **bump**: the bump seed to pass when deriving the PDA | ||
#[allow(unused, clippy::needless_lifetimes)] | ||
pub fn shank_seeds_with_bump<'a>( | ||
game: &'a ::solana_program::pubkey::Pubkey, | ||
bump: &'a [u8; 1], | ||
) -> [&'a [u8]; 3usize] { | ||
[b"tictactoe", game.as_ref(), bump] | ||
} | ||
/// Derives the PDA for this account. | ||
/// | ||
/// * **program_id**: The id of the program | ||
/// * **game**: The key of the game | [Pubkey] | ||
#[allow(unused)] | ||
pub fn shank_pda( | ||
program_id: &::solana_program::pubkey::Pubkey, | ||
game: &::solana_program::pubkey::Pubkey, | ||
) -> (::solana_program::pubkey::Pubkey, u8) { | ||
let seeds = Self::shank_seeds(game); | ||
::solana_program::pubkey::Pubkey::find_program_address(&seeds, program_id) | ||
} | ||
/// Derives the PDA for this account allowing to provide a bump seed. | ||
/// | ||
/// * **program_id**: The id of the program | ||
/// * **game**: The key of the game | [Pubkey] | ||
/// * **bump**: the bump seed to pass when deriving the PDA | ||
#[allow(unused)] | ||
pub fn shank_pda_with_bump( | ||
program_id: &::solana_program::pubkey::Pubkey, | ||
game: &::solana_program::pubkey::Pubkey, | ||
bump: u8, | ||
) -> (::solana_program::pubkey::Pubkey, u8) { | ||
let bump_arg = &[bump]; | ||
let seeds = Self::shank_seeds_with_bump(game, bump_arg); | ||
::solana_program::pubkey::Pubkey::find_program_address(&seeds, program_id) | ||
} | ||
} | ||
``` | ||
|
||
The `.so` size for the different options were recorded + `cargo build-bpf --dump` results | ||
included (differences between dumps are best viewed via `vim -d dump1.txt dump2.txt`): | ||
|
||
- `.so` size with shank that did not generate any code: `90.704K` ([./dumps/01_shank-orig.txt](./dumps/01_shank-orig.txt)) | ||
- `.so` size when not specifying seeds: `90.704K` ([./dumps/02_shank-no-seeds.txt](./dumps/02_shank-no-seeds.txt)) | ||
- `.so` size when specifying seeds without using them: `90.704K` ([./dumps/03_shank-unused-seeds.txt](./dumps/03_shank-unused-seeds.txt)) | ||
- `.so` size when specifying seeds using `seeds_with_bump`: `90.752K` ([./dumps/04_shank-using-seeds-with-bump.txt](./dumps/04_shank-using-seeds-with-bump.txt)) | ||
- `.so` size when specifying seeds using `seeds_with_bump` and removing use of hand-rolled | ||
seeds assignment: `90.704K` ([./dumps/05_shank-using-seeds-with-bump-only.txt](./dumps/05_shank-using-seeds-with-bump-only.txt)) | ||
- `.so` size when using shank pda impl, keeping hand rolled use `90.960K` ([./dumps/06_shank-using-pda-additionally.txt](./dumps/06_shank-using-pda-additionally.txt)) | ||
- `.so` size when using shank pda impl only `90.672K` ([./dumps/07_shank-using-pda-only.txt](./dumps/07_shank-using-pda-only.txt)) |
Oops, something went wrong.