optimizations of histogram computation