google/cayley — pull request #122 by barakmich (2014-08-16 10:44:30+00:00)
Title: Explain Level Logging and Correcting the Cost Model

What started as an experiment into logging statistics on how costs were modeled and number of times Next() and Contains() are called led to some startling issues in the cost model.

First, LinksTo and HasA were not returning a size, meaning Materialize() was having a terrible time being optimized properly.

Second, we underestimated the cost of nexting an And -- if we extract a lot of things and check them against a really fast checker -- no matter how fast that checker is, it's still slower to do that then just next the short list and incur one big, slow check. This is, on some level, a lot of the problem with the helpless checker.

So here's the admirable wins:
```
$ benchcmp mem.txt mempost10.txt
benchmark old ns/op new ns/op delta
BenchmarkNamePredicate 953339 945721 -0.80%
BenchmarkLargeSetsNoIntersection 52055170 39166976 -24.76%
BenchmarkVeryLargeSetsSmallIntersection 354685327 115239993 -67.51%
BenchmarkHelplessContainsChecker 14343004562 27328429 -99.81%
BenchmarkNetAndSpeed 24255647 13095637 -46.01%
BenchmarkKeanuAndNet 17323177 10679583 -38.35%
BenchmarkKeanuAndSpeed 20341470 13855024 -31.89%
BenchmarkKeanuOther 113406332 54019244 -52.37%
BenchmarkKeanuBullockOther 132609072 69745730 -47.41%
```