frigate/frigate
Daniel-dev22 d80d020c86 perf(track): avoid numpy reductions on tiny box lists in position smoothing
update_position runs per tracked object per frame. While a position has
fewer than 10 samples it calls np.percentile four times, and average_boxes
(per stationary object per frame) calls np.mean four times - all on lists of
at most 10 ints, where numpy's per-call dispatch/validation overhead
dominates the actual work.

Replace them with pure-Python equivalents:
- average_boxes: sum()/len() instead of np.mean (bit-identical output)
- interpolated_percentile(): linear-interpolated percentile matching
  numpy.percentile (including its lerp branch at frac>=0.5) for the small
  lists used here, in place of np.percentile

Measured in the release image (numpy 1.26.4) on a 10-element list:
np.percentile 18735 ns -> 191 ns/call (98x); np.mean-based average_boxes
7480 ns -> 591 ns (12.7x); ~74 us saved per object-frame in update_position.
A live py-spy --gil profile of a camera process_frames worker showed
np.percentile (update_position) and np.mean (average_boxes) among the top
Frigate-owned on-CPU frames.

Output is unchanged: added tests assert both helpers are bit-identical to
numpy over randomized small inputs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-20 09:25:04 -04:00
..
api Miscellaneous fixes (#23513) 2026-06-19 10:10:22 -06:00
camera Debug replay resolution (#23287) 2026-05-22 08:39:52 -06:00
comms Restore runtime state on startup (#23326) 2026-05-27 12:03:09 -06:00
config UI tweaks (#23492) 2026-06-16 08:56:52 -05:00
data_processing Miscellaneous fixes (#23177) 2026-05-12 10:20:39 -06:00
db More mypy cleanup (#22658) 2026-03-26 12:54:12 -06:00
detectors Miscellaneous fixes (#23394) 2026-06-04 12:48:58 -06:00
embeddings Debug replay fixes (#23276) 2026-05-21 08:12:53 -06:00
events Miscellaneous fixes (#23335) 2026-05-29 06:53:17 -06:00
genai Allow GenAI providers to be initialized lazily (#23482) 2026-06-14 11:40:33 -05:00
images Replace green screen with error message and force camera_fps to 0 (#4544) 2022-11-28 21:47:20 -06:00
jobs Refactor motion search (#23378) 2026-06-01 12:08:46 -05:00
motion Optimize more mypy classes (#22637) 2026-03-25 12:53:19 -06:00
object_detection Miscellaneous fixes (#23279) 2026-05-22 07:52:01 -06:00
output Refactor move_preview_frames function (#23264) 2026-05-20 10:52:47 -06:00
ptz guard norfair distance against non-finite and zero-area boxes that could crash autotracking cameras (#23475) 2026-06-13 16:23:30 -05:00
record Replace export ffmpeg argument blocklist with a structural allowlist (#23478) 2026-06-13 16:43:22 -06:00
review Inverse mypy and more mypy fixes (#22645) 2026-03-25 19:30:59 -05:00
service_manager Add metrics page for embeddings and face / license plate processing times (#15818) 2025-02-08 12:47:01 -06:00
stats Miscellaneous fixes (#23317) 2026-05-27 09:19:11 -06:00
test perf(track): avoid numpy reductions on tiny box lists in position smoothing 2026-06-20 09:25:04 -04:00
track perf(track): avoid numpy reductions on tiny box lists in position smoothing 2026-06-20 09:25:04 -04:00
util perf(track): avoid numpy reductions on tiny box lists in position smoothing 2026-06-20 09:25:04 -04:00
video Add recording keyframe analysis to camera probe dialog (#23453) 2026-06-11 14:16:41 -06:00
__init__.py app container and config schema 2021-01-26 21:40:33 -06:00
__main__.py Handle SIGINT with forkserver (#18860) 2025-08-16 10:20:33 -05:00
app.py Miscellaneous fixes (#23358) 2026-05-30 21:35:03 -06:00
const.py Improve credential redaction handling (#23265) 2026-05-20 15:59:01 -06:00
debug_replay.py Miscellaneous fixes (#23317) 2026-05-27 09:19:11 -06:00
ffmpeg_presets.py Upgrade ffmpeg to 8 by default (#23393) 2026-06-03 12:28:28 -05:00
log.py Add languages (#21870) 2026-02-03 13:29:52 -06:00
models.py Improve motion review and add motion search (#22253) 2026-03-05 17:53:48 -06:00
mypy.ini More mypy cleanup (#22658) 2026-03-26 12:54:12 -06:00
plus.py fix: upload_image parses response body before checking HTTP status (#22475) 2026-03-16 17:34:30 -06:00
storage.py Improve readability by removing trailing digits caused by floating number conversion (#22934) 2026-04-20 06:35:48 -06:00
timeline.py Display more scores in Tracking Details (#22799) 2026-04-07 10:06:22 -06:00
types.py Media sync API refactor and UI (#21542) 2026-02-26 21:27:56 -07:00
watchdog.py Miscellaneous fixes (#23032) 2026-04-29 16:20:19 -06:00