On Mon, Feb 19, 2018 at 9:29 PM Rob Pike <r...@golang.org> wrote:

> Jesper,
>
> I find myself in rare but mild disagreement about your claims for
> stack-based virtual machines. Please have a look at this short paper about
> the Dis VM from Inferno: http://flint.cs.yale.edu/jvmsem/doc/inferno.ps
>
>
There is a chance I'm just wrong here.

The webassembly paper[0] mentions the size of the program as being
important. They compare this size to older models such as NaCl and asm.js,
and they note the stack based instruction set makes for a smaller "binary
size". However, I have a feeling that a well-engineered VM, register-based
or not, is likely to be able to compete in size of the produced executable.

The obvious reason for wanting that size down is bandwidth usage on the
internet. While caching can play a role, transfer sizes does matter in the
end, especially given mobile.

My experience, though YMMV, is that when a VM is based on registers and
matches a real-world CPU more closely, it is easier to write a compiler/JIT
from the bytecode to the machine instructions. On the other hand, if the VM
is based on a stack, it is easier to write a compiler from a high-level
language to the bytecode. In short, you pick a "split point" of abstraction
and this makes one or the other easier to implement.

Efficiency was not something I touched upon in the post, but I have a hunch
that the experiences of Dis carries over: a VM close to the machine is
easier to get to run fast, with a fraction of the investment.

The brilliance of WebAssembly is that it is really both models in one. The
"transfer format" over the wire is a stack-based instruction set. But the
instructions are built in such a way that we can derive a register machine
from it at any point in the program (statically!). So you obtain a
relatively easy compile target, and small bytecode "binaries". But once you
want to execute the program, you first convert the machine to something
else, probably resembling Dis, and then you proceed to handle that new
machine.



[0]
https://people.mpi-sws.org/~rossberg/papers/Haas,%20Rossberg,%20Schuff,%20Titzer,%20Gohman,%20Wagner,%20Zakai,%20Bastien,%20Holman%20-%20Bringing%20the%20Web%20up%20to%20Speed%20with%20WebAssembly.pdf

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to