You note in the article that the detection occasionally causes some lag in your overall application. Have you looked into a background worker for the task?
We actually discovered that the CPU increase was not caused by the detection, but rather by the CSS animation of the SVG moving around.
It turns out that the detection itself is very fast and lightweight, so there was no need to optimize (background workers would've been a good idea though).
We somewhat optimized the CSS animation, but it's still not where we'd like to be... if anyone on here knows how to improve CSS animation performance beyond dropping frame rate / shortening the animation, I'd love to know. Tried some obvious things (z index, will-change).