gergoerdi / functional-mos6502-web-performance

https://unsafeperform.io/blog/2022-07-02-a_small_benchmark_for_functional_languages_targeting_web_browsers/
https://unsafeperform.io/blog/2022-07-02-a_small_benchmark_for_functional_languages_targeting_web_browsers/
26 stars 5 forks source link

GHCJS implementation #1

Closed nomeata closed 2 years ago

nomeata commented 2 years ago

This compiles and seems to work:

measureAll()
Running JavaScript... 5 main.js:28:25
JavaScript: min: 1ms max: 2ms avg: 1.25ms main.js:42:17
Running ghcjs... 5 main.js:28:25
ghcjs: min: 187ms max: 209ms avg: 191.77ms

I am not sure how idiomatic that is, and if I may be doing something really stupid performance wise.

Also I had to jump through quite a few hoops to get a mutable UInt8Array type, and to expose from Haskell a function that returns a value.

You need ghcjs somehow. nix-shell -p haskell.compilers.ghcjs is one way to get it. Then cabal build --ghcjs works.

I did not fully automate the setup, hence leaving this in Draft state.

Also see https://www.reddit.com/r/haskell/comments/vpnh53/comment/ieoktf0/?utm_source=reddit&utm_medium=web2x&context=3

gergoerdi commented 2 years ago

I'd love to try this out, but I know absolutely nothing about nix... What is missing from my system here?

$ nix-shell -p haskell.compilers.ghcjs
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:13
nomeata commented 2 years ago

How did you install nix? Maybe the installation configured your environment to set NIX_PATH, but you need to re-login for that to take effect?

In any case, this should work:

nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/09c32b0bda4db98d6454e910206188e85d5b04cc.tar.gz -p haskell.compiler.ghcjs

(This is not the most principled way of setting up an environment like this, but one of the fastest one.)

Hmm, it looks like ghcjs is not actually provided by the Nix cache, so this will not only download a bunch of stuff, but also build a bunch of stuff for a while … once you see it doing something, maybe just let it sit there over lunch or so :)

When you come back you should be in a shell with ghcjs installed.

gergoerdi commented 2 years ago

OK I'll try that once I'm over an annoying flu...

Do you have a rough estimate of how much disk size building all of GHCJS via Nix will require?

gergoerdi commented 2 years ago

How did you install nix?

I don't remember doing anything special other than installing it from an Ubuntu .deb.

nomeata commented 2 years ago

I don't remember doing anything special other than installing it from an Ubuntu .deb.

Hmm, then I guess that package does not set up the environment as the official nix installer does.

nomeata commented 2 years ago

Do you have a rough estimate of how much disk size building all of GHCJS via Nix will require?

Hard to predict, but I hope 10-20GB ought to be enough :-D

gergoerdi commented 2 years ago

This got marked as 'merged' by accident, and now I don't know how to reopen it...