-
Notifications
You must be signed in to change notification settings - Fork 196
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
refactor(store,world,world-modules): use BYTE_TO_BITS constant where applicable [N-09] #2015
Conversation
… applicable [N-09]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the changes increase gas cost in a way that makes me doubt if it's worth it. I think the gas cost increase only comes from the places where we replace an inline 8
in code, not in places where we only use it to define another constant that already exists. Maybe a good compromise would be to only change it in those constant definitions where it doesn't impact gas cost, and just add a comment in the other places?
acb64f2
to
f46a5f6
Compare
@alvrs I agree with the direction of adding comments, but the increases actually come from constant definitions(!), not inline code. I've added comments to these files instead, and the gas reports are now equivalent to Specifically, the increase comes from these constants in the Resource ID files:
/// @dev Number of bits reserved for the type in the ResourceId.
uint256 constant TYPE_BITS = 2 * 8;
/// @dev Number of bits reserved for the name in the ResourceId.
uint256 constant NAME_BITS = 32 * 8 - TYPE_BITS;
uint256 constant NAMESPACE_BITS = 14 * 8;
uint256 constant NAME_BITS = 16 * 8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the named constant's purpose is mostly to make the calculations easier to parse for humans; in places where using the constant would increase gas, using a verbose comment instead is an acceptable alternative imo (no need to use the exact same BYTE_TO_BITS
token here since this isn't a value that's ever going to change so we don't need to be able to ie search for it)
No description provided.