Private ReadonlywindowPrivatewindowPrivatestartRecord a network transfer of bytes at the current time. 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).
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 we advance a
startindex past expired entries (O(1) amortized inrate()), and only when the dead prefix exceeds half the buffer do we slice it off in one allocation (record()path). This keeps push amortized O(1) without letting the buffer grow unbounded.