Cherry-pick dorian's optimizations
Merge remote-tracking branch 'kjetilk/faster-hexastore'