Hedgehog-Computing / hedgehog-lab

Run, compile and execute JavaScript for Scientific Computing and Data Visualization TOTALLY TOTALLY TOTALLY in your BROWSER! An open source scientific computing environment for JavaScript TOTALLY in your browser, matrix operations with GPU acceleration, TeX support, data visualization and symbolic computation.
https://hlab.app
Apache License 2.0
2.36k stars 142 forks source link

pref: preload web workers #180

Closed yakunouyang closed 2 years ago

yakunouyang commented 2 years ago

currently, web worker scripts are requested and destroyed every time user clicks Run button, which is time consuming, and cannot be used offline. this pr introduces singleton class for workers, elevating worker scripts requests to page loading.

performance improvement

before:

截屏2022-05-06 03 42 32

plenty of time is wasted while requesting, parsing and compiling scripts, it takes unreasonably ~5secs to run a simple script.

after:

截屏2022-05-06 03 51 34

the running time is reduced to ~0.5secs.

workers will still be destroyed when user terminate running, but re-requests are sent immediately, following run time shouldn't be affected.