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

Rob Hitchens patch -1. Performance and readability. #1

Closed
wants to merge 3 commits into from

Conversation

rob-Hitchens
Copy link

Removed some unnecessary crawling and redundant comparisons for gas optimization.

Added "exists()" and explicit checks to prevent duplicate keys. Replaced z,y,z variables with more descriptive labels to help prepare the rotation and fixup sections for an audit. Removed family-tree items (siblings, grandparents, uncle, etc.) because these are not used by the algo and are of little interest except for debugging (reduces complexity for audit).

This makes it more like a black box with a minimal surface.

Removed the counter because it can be safely externalized. A client app can track the count if it needs to. That squeezes a little more gas out if no one needs the count.

Set up minimalist event logs. The tree itself emits no event, for gas-optimization. A log is implemented at the library client level and reports only the coming and going of key/values which is sufficient to reconstruct an ordered list. This approach is consistent with a philosophy of emitting an event for every important state change. Logs could, arguably, be implemented inside the library to force log emissions but that could be too opinionated and would probably be redundant when clients emit application-level events. We could say the library itself emits no events but the client should, as shown in the example.

Hope it helps.

Removed some unnecessary crawling and redundant comparisons for gas optimization. 

Added "exists()" and explicit checks to prevent duplicate keys. Replaced z,y,z variables with more descriptive labels to help prepare the rotation and fixup sections for an audit. Removed family-tree items (siblings, grandparents, uncle, etc.) because these are not used by the algo and are of little interest except for debugging (reduces complexity for audit). 

This makes it more like a black box with a minimal surface. 

Removed the counter because it can be safely externalized. A client app can track the count if it needs to. That squeezes a little more gas out if no one needs the count. 

Set up minimalist event logs. The tree itself emits no event, for gas-optimization. A log is implemented at the library client level and reports only the coming and going of key/values which is sufficient to reconstruct an ordered list. This approach is consistent with a philosophy of emitting an event for every *important* state change. Logs could, arguably, be implemented inside the library to *force* log emissions but that could be too opinionated and would probably be redundant when clients emit application-level events. We could say the library itself emits no events but the client should, as shown in the example. 

Hope it helps.
n trees managed by a single contract
Update TestBokkyPooBahsRedBlackTree_flattened.sol
@bokkypoobah
Copy link
Owner

Hi @rob-Hitchens , please provide me your ETH address for a bounty resulting from your suggestions above. Thanks!

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

Successfully merging this pull request may close these issues.

2 participants