[erlang-questions] Erlang in the browser

Joe Armstrong erlang@REDACTED
Tue Jan 31 14:31:41 CET 2012

On Tue, Jan 31, 2012 at 11:56 AM, Fredrik Svahn <fredrik.svahn@REDACTED> wrote:
> Hi Joe,
> The Erlang list [1, 2, 3] is represented as js native objects {value:
> 1, next: {value: 2, next: {value: 3, next:nil}}}. The size of a string
> represented as a list is 40 bytes per character in Chromium on my
> x86_64 machine (I do not know if the size would be smaller on a 32 bit
> machine).

How do you know that it is 40 bytes/character? - in fact how do you know the
internal size of any JS object. if I say x = {abc:123, def:"xyz", ...}
etc. how big is this
object in memory - there must be some hidden pointers associated with
x, but without reading
the code for the JS emulator it would be difficult to say how large it is.

> The corresponding number for beam is 16 bytes/char for
> x86_64, I believe, so it is more wasteful as expected. I have
> considered mapping it to js arrays but haven't done any measurements.
> This is just a small script so I did not want to write my own GC, also
> mapping to native objects is better if I later would like to make it
> possible to compile performance critical beams to native javascript
> code.

If memory were a problem you'd need to write the GC and use the beam
memory model ..


> The Erlang tuple {1,2,3} is represented as the js array [1, 2, 3].
> Binaries are mapped to js strings, and atoms to numbers.
> BR /Fredrik
> On Tue, Jan 31, 2012 at 10:24 AM, Joe Armstrong <erlang@REDACTED> wrote:
>> Wow - ultra interesting.
>> Just out of curiosity - how do you represent lists and tuples in JS?
>> Are they represented
>> as  native JS objects or as objects on the beam stack and heap? And if
>> they are native JS objects what is the storage overhead of a
>> list-cell?
>> /Joe
>> On Mon, Jan 30, 2012 at 10:14 PM, Fredrik Svahn <fredrik.svahn@REDACTED> wrote:
>>> There is also http://svahne.github.com/browserl, a small script which
>>> I wrote just for fun.
>>> Short version: it is an Erlang emulator in javascript, which can load
>>> and run an Erlang/OTP system from a tar file with ordinary beam files.
>>> It can also load and execute individual beam files. It will run common
>>> test and successfully complete some OTP test suites (the test suites
>>> are not loaded in the example page, though). Files, binaries, ets and
>>> floats are work in progress, at the moment they are only supported to
>>> the extent needed to boot the system and run common test.
>>> BR /Fredrik
>>> On Tue, Nov 29, 2011 at 12:47 AM, Raoul Duke <raould@REDACTED> wrote:
>>>> wow.
>>>> _______________________________________________
>>>> erlang-questions mailing list
>>>> erlang-questions@REDACTED
>>>> http://erlang.org/mailman/listinfo/erlang-questions
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list