frigate/frigate/util
Daniel d982b3a782
Some checks failed
CI / AMD64 Build (push) Has been cancelled
CI / ARM Build (push) Has been cancelled
CI / Jetson Jetpack 6 (push) Has been cancelled
CI / AMD64 Extra Build (push) Has been cancelled
CI / ARM Extra Build (push) Has been cancelled
CI / Synaptics Build (push) Has been cancelled
CI / Assemble and push default build (push) Has been cancelled
perf(util): use monotonic clock and bounded deque in EventsPerSecond (#23520)
* perf(util): use monotonic clock and bounded deque in EventsPerSecond

EventsPerSecond is updated on every captured frame, every detection and
every processed frame across all cameras and detectors. The previous
implementation derived timestamps from datetime.now().timestamp() (wall
clock), so an NTP or manual clock adjustment could skew the rolling-window
expiry; it also stored timestamps in a list and expired them with
del self._timestamps[0] (O(n) per removal) plus a periodic slice-copy to
cap growth.

Switch to time.monotonic() for the interval math (correct by construction
and immune to wall-clock jumps) and a collections.deque(maxlen=...) so
expiry is O(1) (popleft) and retention is bounded automatically. This
mirrors the deque-based expiry already used in video/ffmpeg.py and
watchdog.py. Observable output is unchanged.

Adds frigate/test/test_builtin.py covering rate calculation, window
expiry and the memory bound.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test: drop test_timestamps_are_memory_bounded

It only asserted that deque(maxlen=) caps length, which is stdlib behavior
rather than something this change needs to verify.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 07:38:41 -06:00
..
__init__.py Fix go2rtc init (#18708) 2025-08-16 10:20:33 -05:00
audio.py Audio transcription support (#18398) 2025-08-16 10:20:33 -05:00
builtin.py perf(util): use monotonic clock and bounded deque in EventsPerSecond (#23520) 2026-06-21 07:38:41 -06:00
camera_cleanup.py Enable event snapshot API to honour query params after event ends (#22375) 2026-03-22 13:33:04 -06:00
classification.py Upgrade ffmpeg to 8 by default (#23393) 2026-06-03 12:28:28 -05:00
config.py Upgrade ffmpeg to 8 by default (#23393) 2026-06-03 12:28:28 -05:00
downloader.py Various Tweaks (#20800) 2025-11-04 17:06:14 -06:00
ffmpeg.py Use Job infrastructure for Debug Replay (#23099) 2026-05-03 14:54:20 -06:00
file.py Enable event snapshot API to honour query params after event ends (#22375) 2026-03-22 13:33:04 -06:00
image.py Debug replay resolution (#23287) 2026-05-22 08:39:52 -06:00
media.py fix: format placeholder in remove_empty_directories debug log (#23147) 2026-05-09 08:35:38 -06:00
model.py Miscellaneous fixes (#20833) 2025-11-07 06:53:27 -07:00
object.py Miscellaneous fixes (#22828) 2026-04-09 20:53:17 -06:00
process.py Miscellaneous fixes (0.17 beta) (#21350) 2025-12-18 15:12:10 -07:00
rknn_converter.py Fixes (#22280) 2026-03-05 14:11:32 -06:00
schema.py Full UI configuration (#22151) 2026-02-27 08:55:36 -07:00
services.py Add recording keyframe analysis to camera probe dialog (#23453) 2026-06-11 14:16:41 -06:00
time.py Fix review summary for DST (#20770) 2025-11-03 07:34:47 -06:00
velocity.py Fixes (#18935) 2025-07-07 06:35:55 -06:00