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
Bytes -> Hex conversion update #21065
Conversation
👋 it seems that this solution is incompatible with the mono build
|
You can guard with How does this method compare to Convert.ToHexString (which would need |
Added an alternate implementation for mono using Did not know I could bump to the |
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.
This reduces time spent in SHA1 hashing during initial load from ~1.4% to 1.2%, which is nice incremental win.
The downside for me is the maintenace burden here. We've added a fair bit of extra code, had to deal with an alternative implementation for mono and added unsafe code. For some larger overall gains I'd say that is worthwhile, but a fraction of a percent in the project overall doesn't sell it for me. Not your fault by any means, if the project was doing like 10-100x more hashing it'd be more tempting.
In this particular case I think you can get a more favourable balance by investigating Convert.ToHexString
or BitConverter.ToString
. Since they'd be no more complex than the current code, it'd be an easy sell even if the performance win isn't quite as good.
The only other place where we use |
Using |
it seems it's incompatible with mono 😩 |
It would seem mono doesn't like me that much 😢. |
LGTM, could you squash the commits? |
added unit test update ToHex(byte[]) to support mono added punctuations to unit test summary and parameter description Replaced with Convert.ToHexString(), public ToHex() + use from Color.ToString() Adjusted back to a simpler mono compatible version only, with lowered allocation
👍🏻 |
Bytes -> Hex conversion update
Hi!
I've updated the functionality which converts a byte array to a lower case hex string.
The performance is improved while still being compatible with the previous version.
For good measure I've added a few unit tests for SHA-1 hashing which uses the wiki examples.
Changes
Affects
Anything that computes a SHA1 hash through CryptoUtil.
Benchmarks
To get an idea of the scaling, I cooked up a little benchmark to test the changes when hashing with SHA-1.
Runs with data sizes of 32 and 128 data sizes.