1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

perf(reader): use a non-cryptographic hash when possible

There is no need to use SHA256 everywhere, especially on small inputs where we
don't care about its cryptographic properties. We're using FNV as it's the
faster available hash in go's standard library, and we're picking its "a"
version as it's slightly better avalanche characteristics, which are
relevant for small inputs.

This commit has the side-effect of invalidating all favicons saved in the
database, which is desirable to benefit from the resize process implemented in
777d0dd2, as it didn't apply retro-actively.

We're also making use of hex.EncodeToString instead of fmt.Sprintf, as it's
marginally faster.

Note that we can't change the usage of sha256 for feed.Hash as it's used to
deduplicate entries in the database.
This commit is contained in:
jvoisin 2025-06-18 15:06:20 +02:00 committed by Frédéric Guillot
parent 9a1d9593b3
commit 86c58e11f6
6 changed files with 16 additions and 12 deletions

View file

@ -161,7 +161,7 @@ func (j *JSONAdapter) BuildFeed(baseURL string) *model.Feed {
for _, value := range []string{item.ID, item.URL, item.ContentText + item.ContentHTML + item.Summary} {
value = strings.TrimSpace(value)
if value != "" {
entry.Hash = crypto.Hash(value)
entry.Hash = crypto.SHA256(value)
break
}
}