Write a function to merge overlapping time-series metric intervals, optimizing for both speed and memory.