Private ReadonlywindowPrivatewindowPrivatestartRecord a network transfer of bytes at the current time. Expires aged-out
entries, then runs the R5 amortized compaction: if the dead prefix is
larger than the live tail, slice it off in one O(n) hit.
Returns current bytes/sec averaged over the trailing window. Also
advances start past any entries that have aged out — amortized O(1).
PrivateexpireAdvance start past every entry older than the window at now.
Sliding-window bandwidth tracker.
Records timestamped byte counts on
record(bytes)and returns the average bytes/sec over the trailingwindowMsonrate().Implementation note (R5 — load-bearing): Naive pruning via Array.shift() is O(n) per pop and degrades to O(n²) under sustained high fetch rates. Instead both
record()andrate()advance astartindex past expired entries (O(1) amortized), and only when the dead prefix exceeds half the buffer doesrecord()slice it off in one allocation. Expiring onrecord()too is what bounds the buffer:rate()is read only while the monitor is visible.