hashes icon indicating copy to clipboard operation
hashes copied to clipboard

perf(k12): remove redundant 8KiB buffer zeroing in process_chunk

Open Galoretka opened this issue 2 months ago • 4 comments

The buffer was zeroed after each full chunk in KangarooTwelveCore::process_chunk(). This is unnecessary because subsequent reads only consume [..bufpos] and bufpos is reset to 0. Removing the memset avoids extra work on long inputs and aligns with the project’s pattern of cleaning sensitive data via Drop under the zeroize feature.

Galoretka avatar Dec 01 '25 14:12 Galoretka

This is unnecessary because subsequent reads only consume [..bufpos]

I would feel better about that if there were a debug_assert_eq!(self.bufpos, CHUNK_SIZE) for the if self.chain_length == 0 above, though I guess if that weren't the case it could be unnecessarily hashing zeros

tarcieri avatar Dec 01 '25 19:12 tarcieri

I wonder why the implementation simply does not use CHUNK_SIZE for block size.

newpavlov avatar Dec 01 '25 19:12 newpavlov

@newpavlov IIUC, the block size is implicitly CHUNK_SIZE unless chaining is being used

tarcieri avatar Dec 02 '25 05:12 tarcieri

This is unnecessary because subsequent reads only consume [..bufpos]

I would feel better about that if there were a debug_assert_eq!(self.bufpos, CHUNK_SIZE) for the if self.chain_length == 0 above, though I guess if that weren't the case it could be unnecessarily hashing zeros

corrected

Galoretka avatar Dec 02 '25 08:12 Galoretka