Summary
doUseCamera redraws camera frames every 100ms and currently performs canvas resize + context lookup on each frame.
Code references
js/utils/utils.js in draw():
canvas.width = w;
canvas.height = h;
canvas.getContext(2d).drawImage(video, 0, 0, w, h);
Why this matters
- Setting
canvas.width/height each frame resets the drawing buffer/state and is expensive.
- Re-fetching
getContext(2d) every frame adds avoidable overhead.
- Combined with periodic capture this increases CPU use, especially on low-power devices.
Expected behavior
- Set
canvas.width/height once during camera/session setup (or only when dimensions change).
- Cache the 2D context once and reuse it in the frame loop.
Suggested fix
Move canvas sizing and context initialization outside draw() and keep draw() limited to drawImage + export logic.