Javascript doesn't support SIMD

I’m making a 3d rendering demo using p5, but I’m depressed because I notice that javascript doesn’t have SIMD and thus cannot perform fast vector caculation. Should I switch to c or c++? p5 is a really good platform and here are some work that I’ve done:


metal and nonmetal using custom shader

sphere light and ambient acclusion

I intended to add raytacing effect using cpu

I’m not sure what you mean by “javascript doesn’t have SIMD.” Web browsers have WebGL, WebGL supports GLSL shaders, GLSL shaders are, in essence, Single Instruction Multiple Data programs. JavaScript vs C++ has got nothing to do with it, since really they are just programming languages. There are some things that OpenGL (which you could use from C++, or JavaScript in Node.js technically) supports, but WebGL does not (such as Geometry Shaders for example). If you really want to do multi-core parallel programming in JavaScript you can look into WebWorkers, but this will not be nearly as performant as a WebGL shader.

If the code can be written to shaders, yes it’s fast. But there are some codes or algorithms that are not easily to be implemented on webgl shaders( for example the ray tracing acceleration structure ). I’m currently doing some vector calculations on cpu, and it heavily relies on the single core performance of cpu. Once there was SIMS.js, but I’m not sure why it’s been abandoned.

Does this help: Fast, parallel applications with WebAssembly SIMD · V8 ? You’ll need to write your SIMD code in a language with a WASM compiler that supports SIMD, but the rest of your code can be JavaScript.

1 Like

It seems still unclear whether it’s available via javascript if I’m right. But thank you anyway. I hope there will be a good solution soon.

Here’s another project you might want to look into: GPU.js - GPU accelerated JavaScript

I wish I had more time to look into some of this because I’m pretty convinced that you could get some really incredible performance out of JavaScript with some of these techniques.

Good luck.

1 Like