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

Implementation of hooks.rs (not) as HashMap #682

Closed
crnch opened this issue Mar 22, 2022 · 2 comments
Closed

Implementation of hooks.rs (not) as HashMap #682

crnch opened this issue Mar 22, 2022 · 2 comments

Comments

@crnch
Copy link

crnch commented Mar 22, 2022

Hi!
Getting to know the libraries while following TerraAcademy, I was wondering why hooks.rs is implemented as a Vec instead of an (allegedly more perfomant) HashMap. Any reasons I'm not seeing? If not, I'd be happy to reimplement :)

@ethanfrey
Copy link
Member

HashMap is not serialisable with our json lib as ordering is not deterministic. Do not use it anywhere.

Also, since the process is "load struct from disk, deserialise, search", any performance gain HashMap would give would be offset by decreased performance of the deserialisation.

The other approach is to store in a cw_storage_plus::Map, but that uses a different key for every item, and is much more expensive if we always want to iterate over all items

@crnch
Copy link
Author

crnch commented Mar 24, 2022

thx @ethanfrey , I appreciate the explainnation! 👍

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