Parallel Programming in JavaScript

SharedArrayBuffer

                    var sab = new SharedArrayBuffer(1024);
                    worker.postMessage(sab);
                
Atomics

                    var int32 = new Int32Array(sab);
                    //worker 1
                    Atomics.add(int32, 0, 1);
                    //worker 2
                    Atomics.add(int32, 0, 1);
                    //worker 3
                    Atomics.add(int32, 0, 1);
                

Demo

Calculate square root

Performance

Single Thread Multi Thread
0 0

Big Demo

three.js demo 1

three.js demo 2

Please don't run all the demos together!

TurboScript

class Vec3 {
   x: float32;
   y: float32;
   z: float32;

   constructor(x: float32, y: float32, z: float32): Vec3 {
       this.x = x;
       this.y = y;
       this.z = z;
       return this;
   }

   add(b: Vec3): Vec3 {
       return new Vec3(
                    this.x + b.x,
                    this.y + b.y,
                    this.z + b.z
                    );
   }
}

export function newVec3(x: float32, y: float32, z: float32): Vec3 {
    return new Vec3(x, y, z);
}

export function addVec3(a:Vec3, b:Vec3): Vec3 {
    return a.add(b);
}

export function destroyVec3(a:Vec3): void {
    delete a;
}

                

Benchmark

THE END

Thank you all

Links

Future WebHPC & Parallel Programming TurboScript playground

Special thanks to MunichJS & Google

This is an experimental technology