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

Redundant identifiers in storage values #5034

Open
nxsaken opened this issue Sep 4, 2024 · 0 comments
Open

Redundant identifiers in storage values #5034

nxsaken opened this issue Sep 4, 2024 · 0 comments
Labels
Enhancement New feature or request

Comments

@nxsaken
Copy link
Contributor

nxsaken commented Sep 4, 2024

We can save space if we remove identifiers from storage values. For example, Storage<AccountId, Account> is really Storage<AccountId, (AccountId, Metadata)>. It also prevents accidentally leaving the world in an inconsistent state by mutating the identifier in the value separately from the key.

This could look like the following:

struct AssetId(...);
enum AssetValue { ... };

struct Asset {
  id: AssetId,
  value: AssetValue,
}

// could be a generic struct representing an `mv` entry
struct AssetEntry<'world> {
  id: &'world AssetId,
  value: &'world AssetValue,
}

struct AssetEntryMut<'world> {
  id: &'world AssetId,
  value: &'world mut AssetValue,
}

struct World {
  assets: Storage<AssetId, AssetValue>,
  ...
}

impl World {
  fn iter_assets(&self) -> impl Iterator<Item = AssetEntry> {
    self.assets().iter().map(|(id, value)| AssetEntry { id, value })
  }

  fn asset_mut(&mut self, id: &AssetId) -> Result<&mut AssetValue, FindError> {
    ...
  }
}

I encountered a problem with queries while trying this: predicates don't seem to support inputs with lifetimes.

Would this be worth pursuing?

@nxsaken nxsaken added the Enhancement New feature or request label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant