Since support for WebAssembly 1.0 was just introduced in the nightly builds of 
Firefox and Chromium, I gave it a try and things look good, at least with 
firefox-nightly. The following nim.cfg 
    
    
    @if emscripten:
      cc = clang
      clang.exe = "emcc"
      clang.linkerexe = "emcc"
      clang.options.linker = ""
      cpu = "i386"
      passC = "-s WASM=1 -s 'BINARYEN_METHOD=\"native-wasm\"' -Iemscripten"
      passL = "-s WASM=1 -Lemscripten -s TOTAL_MEMORY=335544320"
      # use ALLOW_MEMORY_GROWTH=1 instead of TOTAL_MEMORY if performance isn't 
top priority
    @end
    

lets one compile Nim to native wasm by setting -d:emscripten on the command 
line.

Trying something crazy first, I took [Araqs version of JohnS's GC test 
from](https://forum.nim-lang.org/t/2646#16384) and it compiled successfully 
with 
    
    
    nim c -d:useRealtimeGC -d:release -d:emscripten --out=index.html GCBench.nim
    

The result actually seems to work in the broswer, the HTML page has an output 
text area showing this: 
    
    
    Worst push time: 1000000 nano seconds
    [GC] total memory: 275017728
    [GC] occupied memory: 274141184
    [GC] stack scans: 4092
    [GC] stack cells: 1
    [GC] cycle collections: 0
    [GC] max threshold: 0
    [GC] zct capacity: 1024
    [GC] max cycle table size: 0
    [GC] max pause time [ms]: 1
    [GC] max stack size: 64
    

The GC claims it is actually doing something and I am inclined to believe it 

Reply via email to