hugolib: Compare every element in pages cache
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 21 Sep 2018 08:10:11 +0000 (10:10 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 21 Sep 2018 09:21:15 +0000 (11:21 +0200)
commited4f1edbd729bf75af89879b76fbad931693cd67
tree0483fb49078237e0941bb57464969b2a58df63ea
parent058cc6c2c3f72bdc4a703380a6d9cb39afe3dd2f
hugolib: Compare every element in pages cache

It is slightly slower, but correctnes is, of course, more important:

```bash
benchmark                             old ns/op     new ns/op     delta
BenchmarkSortByWeightAndReverse-4     367           645           +75.75%

benchmark                             old allocs     new allocs     delta
BenchmarkSortByWeightAndReverse-4     2              2              +0.00%

benchmark                             old bytes     new bytes     delta
BenchmarkSortByWeightAndReverse-4     64            64            +0.00%
```

Running the same benchmark without any cache (i.e. resorting the slice on every iteration) and then compare it to the current version shows that it still is plenty worth it:

```bash
▶ benchcmp 2.bench 1.bench
benchmark                             old ns/op     new ns/op     delta
BenchmarkSortByWeightAndReverse-4     1358757       645           -99.95%

benchmark                             old allocs     new allocs     delta
BenchmarkSortByWeightAndReverse-4     17159          2              -99.99%

benchmark                             old bytes     new bytes     delta
BenchmarkSortByWeightAndReverse-4     274573        64            -99.98%
```

Closes #5239
hugolib/pageCache.go
hugolib/pageCache_test.go
hugolib/pageSort_test.go
hugolib/pages_related.go