Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Draft data structure #38

Open
loothero opened this issue Feb 23, 2025 · 1 comment
Open

Change Draft data structure #38

loothero opened this issue Feb 23, 2025 · 1 comment

Comments

@loothero
Copy link
Member

The current data structure for Draft is inefficient because each time we pick a card, we re-write all the previous rounds of draft data to storage. Furthermore, the use of Span<> prevents us from leveraging IntrospectPacking such that every u8 option and u8 card is consuming an entire storage slot.

By using a hashmap, we can prevent rewriting previous data each time a new card is selected. Furthermore, by storing the seed which can be used to produce the card options instead of the actual card ids, we can eliminate the other span and pack Draft into a single storage slot

#[derive(Copy, Drop, Serde, IntrospectPacked)]
#[dojo::model]
pub struct Draft {
    #[key]
    game_id: u64,
    #[key]
    draft_round: u8,
    selected_card: u8
    seed: u128
}

With a simple helper function, we can still generate a Span<u8> of the cards or options when needed but the storage, and therefore gas, of the above data structure will be significantly more efficient.  
@Await-0x
Copy link
Member

Await-0x commented Mar 3, 2025

For this to work, we also need to store the current draft_count somewhere

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

No branches or pull requests

2 participants