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

Optimize state key conversion #2989

Closed
greymistcube opened this issue Mar 25, 2023 · 0 comments
Closed

Optimize state key conversion #2989

greymistcube opened this issue Mar 25, 2023 · 0 comments

Comments

@greymistcube
Copy link
Contributor

When converting an Address to state key, we convert the given Address to a lower hex string.

I've benchmarked the following methods:

Method 1:

ToStateKey(Address address) => address.ToHex().ToLowerInvariant();

Method 2:

ToStateKey(Address address) => ByteUtil.Hex(address);
Method Mean Error StdDev
Method1 257.97 ms 5.712 ms 16.480 ms
Method2 38.80 ms 0.775 ms 1.857 ms

As we can see, it is at least 6 times faster. 🙃

As ByteUtil.Hex() already outputs a lower cased hex string, there is no need to "lower" post-checksum. Also, in the case above ToLower() would suffice as hex representation is culture insensitive. 🙄

Also, as a side note, we should be more specific with the method documentation for ByteUtil.Hex() that it specifically outputs a lower cased hex string. 😗

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

1 participant