scp-fs2open / fsoinstaller

The Java installer for FS2_Open and the collection of mods from the Hard Light Productions community.
12 stars 8 forks source link

Avoid computing file hashes concurrently #10

Closed asarium closed 6 years ago

asarium commented 6 years ago

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.

Goober5000 commented 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.

asarium commented 6 years ago

I changed to code so that it locks the computeHash operations instead.

Goober5000 commented 6 years ago

Looks good, but can you use the aligned brace style? This would keep it consistent with the rest of the codebase.

asarium commented 6 years ago

Fixed.