You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
The text was updated successfully, but these errors were encountered: