Skip to content

Commit

Permalink
Merge branch 'master' into publish-idl
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus authored Jan 4, 2024
2 parents e8d8939 + 4e513f7 commit 607faae
Show file tree
Hide file tree
Showing 98 changed files with 95,574 additions and 217 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build+test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest-16-cores, windows-latest-8-cores, macos-latest]
include:
- os: ubuntu-latest
RUST: nightly
RUST: stable

- os: windows-latest
RUST: nightly
RUST: stable

- os: macos-latest
RUST: nightly
RUST: stable

steps:
- uses: hecrj/setup-rust-action@v1
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/target
**/Cargo.lock
/.idea/
**/.DS_Store
9 changes: 4 additions & 5 deletions Cargo.toml
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/"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ For _usage_ and _installation_ see the [shank-cli Readme](./shank-cli/README.md)
- [shank-macro-impl](./shank-macro-impl) implements and tests the _derive_ macros
- [shank-idl](./shank-idl) processes files of a crate in order to discover _shank_ macros
annotations and convert annotated types into an [solita](https://github.com/metaplex-foundation/solita) compatible IDL
- [shank-render](./shank-render) generates Rust `impl` blocks from specific annotations like
account `seeds`

## Development

Expand Down
100 changes: 100 additions & 0 deletions diagnostics/pda/README.md
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))
Loading

0 comments on commit 607faae

Please sign in to comment.