Use a fenwick tree to optimize prefix sums
💬
by Caio 7 years ago
This patch makes summary use the excellent fenwick package from
https://github.com/yourbasic/fenwick to dramatically speed
up Add() calls while adding a bounded cost to memory.
benchmark old ns/op new ns/op delta
BenchmarkAdd1-4 187 206 +10.16%
BenchmarkAdd10-4 332 274 -17.47%
BenchmarkAdd100-4 1092 325 -70.24%
The tree creation could be faster, but profiling has shown that
it doesn't seem to be that much of a problem (that's because
`summary.setAt()` happens a *lot* more than `summary.Add()`)