Closed camilstaps closed 2 years ago
Any idea why I might be unable to build this on a fresh install of Clean and Nitril?
Never mind, turns out I had clm
installed in my $HOME/bin
from back in 2008 when I last played with it at uni :D
Good stuff. Merged in c4bab9076ab8fef9ae4cd9256fed4b402ab7dd46. For what it's worth, I'm seeing 40ms; but then again, if you look at my blogpost, I also had to update the JS number because for some reason I see faster numbers now...
Cool, thanks!
tl;dr: this adds an implementation in Clean which can be interpreted in WebAssembly. Benchmark result corrected for machine differences is 52.79ms; significantly slower than Idris but faster than TypeScript and Asterius. Code size is average.
I don't know if you're interested in pull requests for other languages, so feel free to ignore this. However, when I saw this project announced on the Haskell Weekly I thought it could be a nice larger benchmark to compare the WebAssembly interpreter for Clean with backends for other languages. Of course, it should be noted that this is an interpreter backend and the others are (AFAIK) all compilers.
Clean is a functional programming language similar to Haskell. It compiles through an intermediate language for an abstract machine based on graph rewriting, the ABC machine. It is possible to run Clean in the browser through WebAssembly with an interpreter for the ABC machine. For more details, see the interpreter repository and doi:10.1145/3412932.3412941.
Some notes about the implementation:
*
in*CPU
) for mutability. Values of a unique type are guaranteed to be referred to only once, so that they can be updated in place. This allows fast updates of CPU registers and memory. This is the standard way to implement something like this in Clean, rather than usingIORef
s or hiding mutability in a monad.I compared my results with the JavaScript implementation, which was the easiest to set up for me. This gives 1.61ms for JavaScript and 40.09ms for Clean. The time reported for JavaScript on your blog is 2.12ms, so corrected for that Clean has 2.12/1.61*40.09 = 52.79ms.
Some other notes:
ArrayBuffer
to the WebAssembly heap. I am primarily interested in the speed of the backend, so I would be interested in a program that runs for more than ±4000 instruction cycles. I haven't looked at the Asterius code, but something similar may be going on there. The other backends target JavaScript, so they don't need to copy the buffer.