Replace the MD5 hashing of images with xxHash

Note that we only use this for change detection.

The previous implementation invoked `MD5FromReaderFast` that created a MD5 has from 8 64 bytes chunks in the file, which is obviously very fast. The new implementation creates the hash from the entire file and ... seems to be even more effective:

```
name          old time/op    new time/op    delta
HashImage-10    9.45µs ±21%   10.89µs ± 1%     ~     (p=0.343 n=4+4)

name          old alloc/op   new alloc/op   delta
HashImage-10      144B ± 0%        8B ± 0%  -94.44%  (p=0.029 n=4+4)

name          old allocs/op  new allocs/op  delta
HashImage-10      4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.029 n=4+4)
```
This commit is contained in:
Bjørn Erik Pedersen
2024-07-30 12:52:54 +02:00
parent 8b5d796989
commit d5eda13cb2
7 changed files with 180 additions and 29 deletions

View File

@@ -493,7 +493,7 @@ func (i *imageResource) relTargetPathFromConfig(conf images.ImageConfig) interna
}
h := i.hash()
idStr := fmt.Sprintf("_hu%s_%d", h, i.size())
idStr := fmt.Sprintf("_hu%d_%d", h, i.size())
// Do not change for no good reason.
const md5Threshold = 100