

Purity in Parallel JavaScript
source link: http://smallcultfollowing.com/babysteps/blog/2012/10/24/purity-in-parallel-javascript/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Purity in Parallel JavaScript
Oct 24, 2012
I can’t believe I’m saying this, but I’ve started to think that
Parallel JS (nee Rivertrail) should not demand pure callbacks to
functions like map()
and so forth. Rather it should just accept
arbitrary functions. Previously, I thought that it was important that
ParallelArray
methods should only accept functions which, at least
in a perfect world, would be safely parallelizable. But I am no
longer so sure why that is an important goal. Here is my reasoning.
First, we always retain the right to execute sequentially. If we’re
executing sequentially, it’s actively harder to enforce purity than
it is to permit mutation—we will have to put in place some kind of
proxying or write monitoring. I would really like it if using
ParallelArray
methods was never slower than writing an equivalent
for loop in JavaScript. That is, writing parallel_array.map(f)
should not be slower than normal_array.map(f)
. But if we have to
impose write monitoring, it will almost certainly be slower, in the
event that we cannot parallelize. It will also be less general.
Second, it’s not clear to me what negative side effect (no pun intended) comes of permitting mutation in the callbacks. In cases where we can tell at compile time that the function is safe, we can permit it to execute in parallel. In cases where we cannot, we can speculatively run in parallel and then monitor the suspicious writes (as indeed we do today). If we detect a violation, it just means we fallback to sequential (just as we do today). It’s not like telling users they are not supposed to write to shared data means that they will not; ultimately, we must always be ready to enforce this contract dynamically, so the only question is what happens when we detect a violation.
Recommend
-
21
Haskell can do anything your mainstream programming language can. Purity is not about preventing side effects (a database query or an http request), it's about having a clear boundary between...
-
20
Clang and GCC (and others) support function attributes __attribute__((const)) and __attribute__((pure)) . These had always been explained to me thus: __attribute__((pure...
-
5
Extending the definition of purity in Rust Oct 12, 2012 In this post I propose an extension of Rust’s purity rules. The short version is that pure functions would be allowed to mutate data owned by their
-
7
Purity in the EVM This document provides a definition of purity suitable for a signature validation contract. It provides resources for designing an on-chain purity-checking contract. This document is not offi...
-
8
Discerning and maintaining purity Functional programming depends on referential transparency, but identifying and keeping functions pure requires deliberate attention.
-
11
A lost paradise of purity Terror and transcendence in the late masterpieces of Schubert Of all the premature deaths among...
-
7
Wednesday, 17 February 2021 01:01 Pure updates Purity, adds to FlashArray range Featured By Stephen Wither...
-
8
Functional Programming is based on pure functions, which have several good qualities that make for better code. However, usual practices don’t normally apply them, with consequent difficulties and problems. In this article we’ll explain what...
-
8
-
12
Premium Chakra UI & React DashboardPurity UI Dashboard PRO is an innovative ReactJS Premium Dashboard based on Chakra UI that will help you create stunning websites & web apps in minutes. ✅ 300 fully coded elemen...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK