As discussed briefly last week with @morcos and @sdaftuar. Rather than jumping around, visit elements in-order. This produces a noticeable speedup.
I added the assertions because it’s not entirely clear from the existing code if the bucket size is allowed to differ from the individual sizes. I can’t imagine that that could be the case, so I’ll remove them if preferred.
Additionally, I assume we could skip UpdateMovingAverages() altogether if no entries have ever been added, but it’s not obvious to me how to do that without breaking something.