-
Notifications
You must be signed in to change notification settings - Fork 2.6k
chore: reduce copy times for bytes in core-hashing #13519
chore: reduce copy times for bytes in core-hashing #13519
Conversation
/// Do a Blake2 64-bit hash and place result in `dest`. | ||
pub fn blake2_64_into(data: &[u8], dest: &mut [u8; 8]) { | ||
type Blake2b64 = blake2::Blake2b<U8>; |
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.
Are the *_into(data, dest)
family of functions relevant?
Looks like are not used anywere in the codebase and is some user requires something like that it can easily construct it
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.
Do you means that should I remove these xx_into
functions?
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.
I usually tend to follow YAGNI principle.
But with that I'm not saying that should be a dogma.
I have the (maybe bad?!) attitude to remove unused code especially the trivial bloat that can be trivially implemented using a line of code by the user 😃
Besides checking the assembly there's also a benchmark in |
IMO copying 32 or 64 bytes in a modern machine is so fast that maybe the difference is hard to be appreciated. Nevertheless I'm almost always ok to code pruning if there are no functional changes |
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.
👍
Yeah, I agree, I was mostly just suggesting that as a curiosity as nevertheless it'd be nice to know. |
bot merge |
@yjhmelody Thanks! |
* chore: reduce copy bytes for core-hashing * improve by suggestions and remove unused `xx_into` * chore: replace sha2 crate by `sp_core::hashing` for pallet-alliance * fix features * use sp-core-hashing directly * add to dev-dep
* chore: reduce copy bytes for core-hashing * improve by suggestions and remove unused `xx_into` * chore: replace sha2 crate by `sp_core::hashing` for pallet-alliance * fix features * use sp-core-hashing directly * add to dev-dep
copy_from_slice
) will be erased by rust compiler, so I improve the hash code by hand.