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

Cache hash tree root computation #17

Open
ralexstokes opened this issue May 28, 2022 · 3 comments · May be fixed by #152
Open

Cache hash tree root computation #17

ralexstokes opened this issue May 28, 2022 · 3 comments · May be fixed by #152
Labels
enhancement New feature or request

Comments

@ralexstokes
Copy link
Owner

ralexstokes commented May 28, 2022

some design questions:

which types?

List and Vector are good targets -- the other custom types provided here are small enough to not need caching given the complexity it would entail (lots of wrapping etc)

An interesting one is containers with the SimpleSerialize proc macro...

One option is an attribute macro to change the struct definition in-place

Another option is to modify the derive macro so that it has a helper attribute and then it is on the caller to include the cache as needed (using the attribute to signal to the derive macro it should be used when computing the hash tree root).

I personally lean towards this last option at the moment as it is explicit and gives the caller the most flexibility on how to add caching to their custom types.

mutability model?

interior or exterior mutability? the cleanest thing would be to encapsulate all of the mutable caching behind an immutable type

relevant data to consider:

@ralexstokes ralexstokes added this to the v1.0.0 milestone Jan 13, 2023
@ralexstokes ralexstokes removed this from the v1.0.0 milestone Jun 5, 2023
@ralexstokes
Copy link
Owner Author

partial implementation deleted in the one commit of #74

could be a good starting place to pick this back up when perf becomes an issue

@ralexstokes ralexstokes changed the title support some kind of caching w/ the "Merkle backing" for Merkleized types cache hash tree root computation for List and Vector types Jun 8, 2023
@ralexstokes ralexstokes changed the title cache hash tree root computation for List and Vector types cache hash tree root computation Jun 8, 2023
@ralexstokes ralexstokes added the enhancement New feature or request label Mar 30, 2024
@ralexstokes
Copy link
Owner Author

see #6 for an initial direction here

@ralexstokes
Copy link
Owner Author

some current thoughts:

  1. consider putting the cache behind an immutable wrapper, in which case HashTreeRoot::hash_tree_root could take an immutable reference as well -- this has implications for all the consumer crates of this one so it would imply quite a substantial code refactor down the line...

  2. a "lightweight" version of caching here just caches the root of the tree and marks any leaf elements that are "dirtied". a more substantial version would cache the entire Merkle tree alongside the data structure to make the hash tree computation even more efficient in terms of compute. an even more sophisticated option would support "journaling" writes so it becomes easy to undo mutations.

@ralexstokes ralexstokes changed the title cache hash tree root computation Cache hash tree root computation Apr 1, 2024
@ralexstokes ralexstokes linked a pull request Apr 14, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant