brownhci / WebGazer

WebGazer.js: Scalable Webcam EyeTracking Using User Interactions
https://webgazer.cs.brown.edu
Other
3.54k stars 536 forks source link

Refactor: replace numeric with mathjs #225

Closed idiotWu closed 3 years ago

idiotWu commented 3 years ago

Resolves #211.

This PR replaced numeric with mathjs to fix the CSP error as mentioned in #211. I'm not able to run the test script because files under www/data/src/P_01/ are missing, but the demo pages seem to be working.

As a side effect, the bundle size increased from 2.1M to 3.2M (both minified).

Skylion007 commented 3 years ago

Yeah, I found that Math.js wraps normal JS arrays. Hence why it's slow. It also doesn't do a lot of optimizations. It seems to be more focused on correctness and extensibility than speed sadly.

Instead of reimplementing all these ourselves, I would like to see if there is a well-supported LinAlg library we can leverage. At the very least, we are using arrays of arrays in JS which are really slow, so anything that doesn't use those should perform faster.

@idiotWu It may be overkill but how does the benchmarking for Eigen.JS look? https://github.com/BertrandBev/eigen-js

Skylion007 commented 3 years ago

Here is there official benchmarking: https://bertrandbev.github.io/eigen-js/#/benchmark

idiotWu commented 3 years ago

@Skylion007

At the very least, we are using arrays of arrays in JS which are really slow, so anything that doesn't use those should perform faster.

Well, JS native arrays are actually fast on modern browsers. I thought TypedArray based implement would be faster, but in my tests ml-matrix (the only TypedArray based linalg lib I've found so far) does not seem to be much faster than math.js. What's more, a total refactoring is necessary if we want to use TypedArray.

Eigen.js seems to be as slow as math.js: image

istvan73 commented 2 years ago

@idiotWu

I just dropped in to say a big THANK YOU! You've solved the issue which held me back from making my chrome extension. I am super grateful, and going to mention your code as well when the extension will be out.

Istvan

koll93 commented 2 years ago

@idiotWu Thanks. I needed to use webgaizer in google extension with manifest v3 but with new model with landmarks. I used @idiotWu's idea for the latest revision of the webgaizer. https://github.com/koll93/WebGazer/tree/refactor-remove-numeric-landmarks