Scripta-Qumranica-Electronica / Scrollery-website

SQE website
MIT License
3 stars 2 forks source link

GPU acceleration for Masks #61

Open Bronson-Brown-deVost opened 6 years ago

Bronson-Brown-deVost commented 6 years ago

We could probably speed up the site a bit by offloading the Potrace algorithm as well as some of the vector conversion algorithms to the GPU. See https://github.com/gpujs/gpu.js and https://github.com/MaiaVictor/WebMonkeys for possible libraries.

sjones6 commented 6 years ago

I'd be happy to see this. But, before doing it, if we could get some metrics recorded about performance of the current algorithm runtime in the render thread. (The window.performance and console.time and console.timeEnd should be helpful in this regard.) If possible, considering both memory pressure and time would be helpful, but I'd be satisfied just with some time measurements.

sjones6 commented 6 years ago

I've just had another thought on how to approach this that I think is worthy of consideration:

You can compile C or C++ into WebAssembly (as well as Rust, and maybe another couple languages). WebAssembly is supported by 4 major browser vendors, but not IE, and in all of them, is able to run with only slightly slowdown from executing them right on the CPU. Could we find a C/C++ implementation of the Potrace algorithm which we can compile to WebAssembly and include that into the project?

In the cases where the browser supports it, we can use the WebAssembly version and in the cases that the browser does not (just use feature sniffing I imagine), then we fall back to JS version.

WebAssembly is particularly suited for heavy image manipulation so it might be something to seriously consider, whether for this purpose or not.

sjones6 commented 6 years ago

It appears the original implementation is in C (not surprising): http://potrace.sourceforge.net/

Bronson-Brown-deVost commented 6 years ago

Yeah! That would be a lot of fun! When we get a little bit of time, let's play around with it. I've been looking for an excuse to use webassembly.

sjones6 commented 6 years ago

I tried out a Rust > WebAssembly thing yesterday, and a simple increment function was about 3-4x faster. The setup is the most onerous part to get all the compilers working out. Webpack is increasingly adding support but still, information is spotty. I didn't try and C/C++ as that seems a bit more involved (just installing emscripten appears to take about 2 hours ...).