lastmjs / software-issues

1 stars 0 forks source link

Massive localized parallelization made possible by immutable data #43

Open lastmjs opened 7 years ago

lastmjs commented 7 years ago

If you can ensure that values are immutable, and that expressions have no side effects, could you possibly automatically and arbitrarily for any program with such properties, parallelize the execution of the program? I'm imagining that if you use immutable data, the compiler or interpreter could automatically break up expressions and run them in parallel, potentially increasing the speed of your programs greatly. Is there a way to do this automatically for arbitrary programs? Perhaps we would need to start with languages that support immutable data, and then move on from there, of course ending up at JavaScript. Starting with a lisp might be a good idea (Clojure)? Then we could compile to JavaScript.

lastmjs commented 7 years ago

To get this to work for JavaScript, we could turn the JS into an abstract syntax tree, and then check each statement or expression to see if it depends on any previous values. If the expression does not depend on any previous values, throw it into a thread and execute it. We might also need to ensure that the expression is pure. If an expression does depend on previous values, figure out how to wait until the values are created from the other threads running. I'm thinking we could implement this engine in C++ because of potential nice async/await syntax for threads, and being able to easily integrate it with Node.js. C might be a better choice though, since it is a simpler language and doesn't have all of the unnecessary OO stuff. We could also then compile the library to wasm, and hopefully run it universally in the browser and Node.js. Maybe the initial version should just be written in JavaScript and use web workers as the threading mechanism. That probably won't be as performant as we need, as in it might not have any performance gains because of potential overhead with web workers threads. To test all of this, we might be able to use the ECMAScript or wasm test cases. Run any code from the tests with this library, and if we can get all of the tests to pass then hopefully we've created a functionally equivalent implementation.

lastmjs commented 7 years ago

Read research papers on the subject. A good Google search to start with is parallelizing arbitrary programs