Closed asarium closed 6 years ago
Excellent observation! That hadn't occurred to me, but you're absolutely right. Thank you.
However, I wonder if it would be better to add the lock within IOUtils.computeHash
(specifically, surrounding the FileInputStream
operations). This is because mod patching, which also uses the hash function, could be running concurrently.
I changed to code so that it locks the computeHash
operations instead.
Looks good, but can you use the aligned brace style? This would keep it consistent with the rest of the codebase.
Fixed.
Computing the hashes concurrently decreases overall hashing performance since the OS has to do a lot of seek operations on the disk to allow all hashing operations to operate in sequence. This is especially harmful on HDDs.
This uses a standard Java lock to ensure that only onc hash is computed at a time which improved hash performance immensely for me.