Live data from Hacker News

WebAssembly 101: A developer’s first steps

blog.openbloc.fr

81–90 of 153 posts

Re: WebAssembly 101: A developer’s first steps

#81

Earlier quoted context omitted.

Javascript is fine, but as you already know, everybody wants to use his/her language of choice. And, more importantly, everybody should be able to choose the right language for the specific task. What could happen, with WebAssembly, is the opposite: A wane in Javascript's popularity.

What could happen, with WebAssembly, is the opposite: A wane in Javascript's popularity. If the right moves happen, possible. If the wrong moves happen, it will be the second coming of plugins. Languages based on WebAssembly have to be 1st class citizens in the browser infrastructure, otherwise it will be a repeat. This means that debugging has to be transparent. Access to the DOM has to be ultimately the same.

"If the wrong moves happen, it will be the second coming of plugins. "

Oh my god, you sent me a flashback to the evil days of the Plugin-Based-Internet...

.. the days of Flash versus Shockwave versus ActiveX versus Java Applet!!

Re: WebAssembly 101: A developer’s first steps

#84
post #69

I wonder where the world is going with this. At first glance it looks like webassembly is a potential faster replacement for javascript in the browser. However, javascript is an increasingly popular language everywhere. I'm not sure people will want to move away from it for most development. The part that is actually causing performance problems with web application is the HTML/CSS/DOM layer which was not designed as…

> I'm not sure people will want to move away from it for most development. x = 1 + '2' //12 x = 1 - '2' //-1 Oh yes, yes we do.

I mean, I agree with you but that's not even that bad of an example. I would expect many languages to do something similar. Something like this might be a better example:

    "\t\r\n" == 0                 → true
    "\t\r\n 16 \t\r\n" == 16      → true
    "\t\r\n 16 \t\r\n" == "16"    → false

Re: WebAssembly 101: A developer’s first steps

#85

I recommend anyone wanting to experiment with WASM to check out https://github.com/dcodeIO/webassembly which takes a lot of pain out of setting up the toolchain and lets you produce much leaner binaries as well. Also keep an eye on https://github.com/dcodeIO/AssemblyScript :)

This AssemblyScript thing looks like some nice idea for being able to work with a single language while still being able to compile some computationally-heavy but otherwise small modules down to WASM and using them later from JS/TS as an external module.

I'm curious how this approach looks from an optimization point of view? I guess emscripten/LLVM can do more optimization than this the AssemblyScript/binaryen toolchain, and when one puts already the effort in for using WASM the goal should probably be to have as much optimization as possible.

Re: WebAssembly 101: A developer’s first steps

#86
post #84
post #69

Earlier quoted context omitted.

> I'm not sure people will want to move away from it for most development. x = 1 + '2' //12 x = 1 - '2' //-1 Oh yes, yes we do.

I mean, I agree with you but that's not even that bad of an example. I would expect many languages to do something similar. Something like this might be a better example: "\t\r\n" == 0 → true "\t\r\n 16 \t\r\n" == 16 → true "\t\r\n 16 \t\r\n" == "16" → false

No, I don't think most languages do something similar.

Re: WebAssembly 101: A developer’s first steps

#87

I wonder where the world is going with this. At first glance it looks like webassembly is a potential faster replacement for javascript in the browser. However, javascript is an increasingly popular language everywhere. I'm not sure people will want to move away from it for most development. The part that is actually causing performance problems with web application is the HTML/CSS/DOM layer which was not designed as…

For me the main potential of asm.js/WebAssembly does not lie in the fact that it is faster, but in that it provides us with a way to run native C/C++ code inside the browser without adapting it (much), and doing this at a speed which is not (much) worse than the speed of the original code. This in turn makes functionality that was traditionally very hard to get in a browser/JS environment suddenly very easy to get: -…

I thought the problem with client side crypto wasn't so much performance but the fact that it can't really be trusted?

Re: WebAssembly 101: A developer’s first steps

#88
post #62

Earlier quoted context omitted.

I'd wager a lot of this popularity is correlation, not causation. A lot of its popularity stems from being the dominant browser scripting language. This causes it to be popular with back-end frameworks for code re-use and shared developer skill. This causes it to be popular with, say, database engines that are used by the back-end, and so on and so forth. WebAssembly is the first steps to truly breaking that chokehol…

Right, however javascript will still be the only full featured language having its runtime and libraries included with the browser. That means that for other languages, only the ones with fairly light runtimes and libraries could be suitable for inclusion in most web apps. This will limit the choices for non javascript general development. It may be possible to do a webassembly/webgl rendering engine to replace html/…

Most news sources already load between 2 and 10 megabytes of Javascript, which is a significant fraction of, say, Python's runtime and many, many people browse those pages on mobile devices and connections without a problem. In Python's case, a large amount of the runtime size is taken up by all of the platform specific implementations of the standard library and they wouldn't work in the sandbox anyway.

Is there anything preventing Python.org from hosting the runtime environment on their CDN that everyone caches locally? Are there security issues from cross domain modules? Worst case, I don't think it would be hard to extend the LocalStorage API to cache modules between domains (perhaps with signed runtimes and a fallback).

Re: WebAssembly 101: A developer’s first steps

#89

I recommend anyone wanting to experiment with WASM to check out https://github.com/dcodeIO/webassembly which takes a lot of pain out of setting up the toolchain and lets you produce much leaner binaries as well. Also keep an eye on https://github.com/dcodeIO/AssemblyScript :)

This AssemblyScript thing looks like some nice idea for being able to work with a single language while still being able to compile some computationally-heavy but otherwise small modules down to WASM and using them later from JS/TS as an external module. I'm curious how this approach looks from an optimization point of view? I guess emscripten/LLVM can do more optimization than this the AssemblyScript/binaryen toolch…

Hard to be sure without measurements, but emscripten uses LLVM's optimizer and the binaryen optimizer, and AssemblyScript can benefit from the latter. So the question is how much the LLVM optimizer could help this type of code.

For example, the LLVM optimizer can do smart things with aliasing and assumptions about undefined behavior in C code, but for a language like AssemblyScript those might not be relevant anyhow.

But currently the binaryen optimizer is still missing some passes like GVN, so until we add those, that might be noticeable when doing comparisons here.

Re: WebAssembly 101: A developer’s first steps

#90
post #84
post #69

Earlier quoted context omitted.

> I'm not sure people will want to move away from it for most development. x = 1 + '2' //12 x = 1 - '2' //-1 Oh yes, yes we do.

I mean, I agree with you but that's not even that bad of an example. I would expect many languages to do something similar. Something like this might be a better example: "\t\r\n" == 0 → true "\t\r\n 16 \t\r\n" == 16 → true "\t\r\n 16 \t\r\n" == "16" → false

> I would expect many languages to do something similar.

Of the common dynamic languages I can think of, the only ones that do something similar are Perl/Perl6 and PHP, and even they are still saner than JS.

    $ $((1+\2))
      bash: 1+\2: syntax error: operand expected (error token is "\2")
    $ $((1-\2))
      bash: 1-\2: syntax error: operand expected (error token is "\2")
    $ ruby -e"1+'2'"
      -e:1:in `+': String can't be coerced into Integer (TypeError)
      from -e:1:in `'
    $ ruby -e"1-'2'"
      -e:1:in `-': String can't be coerced into Integer (TypeError)
      from -e:1:in `'
    $ python3 -c"1+'2'"
      Traceback (most recent call last):
        File "", line 1, in 
      TypeError: unsupported operand type(s) for +: 'int' and 'str'
    $ python3 -c"1-'2'"
      Traceback (most recent call last):
        File "", line 1, in 
      TypeError: unsupported operand type(s) for -: 'int' and 'str'
        >>> exit()
    $ python2 -c"1+'2'"
      Traceback (most recent call last):
        File "", line 1, in 
      TypeError: unsupported operand type(s) for +: 'int' and 'str'
    $ python2 -c"1-'2'"
      Traceback (most recent call last):
        File "", line 1, in 
      TypeError: unsupported operand type(s) for -: 'int' and 'str'
    $ perl -e'print 1+"2"."\n"'
      3
    $ perl -e'print 1-"2"."\n"'
      -1
    $ perl6 -e"say 1+'2'"          
      3
    $ perl6 -e"say 1-'2'"
      -1
    $ php -r'echo 1+"2","\n";'
      3
    $ php -r'echo 1-"2","\n";'
      -1
    $ racket -e '(+ 1 "2")'
      +: contract violation
        expected: number?
        given: "2"
        argument position: 2nd
        other arguments...:
         1
    $ racket -e '(- 1 "2")'
      -: contract violation
        expected: number?
        given: "2"
        argument position: 2nd
        other arguments...:
         1
    $ sbcl
      This is SBCL 1.3.18, an implementation of ANSI Common Lisp.
      More information about SBCL is available at .

      SBCL is free software, provided as is, with absolutely no warranty.
      It is mostly in the public domain; some portions are provided under
      BSD-style licenses.  See the CREDITS and COPYING files in the
      distribution for more information.
      * (+ 1 "2")

      debugger invoked on a TYPE-ERROR in thread
      #:
        The value
          "2"
        is not of type
          NUMBER
        when binding SB-KERNEL::Y

      Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

      restarts (invokable by number or by possibly-abbreviated name):
        0: [ABORT] Exit debugger, returning to top level.

      (SB-KERNEL:TWO-ARG-+ 1 "2") [external]
      0] 0

      * (- 1 "2")

      debugger invoked on a TYPE-ERROR in thread
      #:
        The value
          "2"
        is not of type
          NUMBER
        when binding SB-KERNEL::Y

      Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

      restarts (invokable by number or by possibly-abbreviated name):
        0: [ABORT] Exit debugger, returning to top level.

      (SB-KERNEL:TWO-ARG-- 1 "2") [external]
      0] 0

      * (exit)
    $ erl
      Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

      Eshell V8.3  (abort with ^G)
      1> 1+"2".
      ** exception error: an error occurred when evaluating an arithmetic expression
           in operator  +/2
              called as 1 + "2"
      2> 1-"2".
      ** exception error: an error occurred when evaluating an arithmetic expression
           in operator  -/2
              called as 1 - "2"
      3> halt().
    $ elixir -e '1+"2"'
      ** (ArithmeticError) bad argument in arithmetic expression
          :erlang.+(1, "2")
          (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
          (elixir) lib/code.ex:170: Code.eval_string/3

    $ elixir -e '1-"2"'
      ** (ArithmeticError) bad argument in arithmetic expression
          :erlang.-(1, "2")
          (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
          (elixir) lib/code.ex:170: Code.eval_string/3
Post reply on HN