News for hackers. Stuff that matters.
Re:What makes WebAssembly fast? by ClassyJacket on Tuesday February 28, 2017 @08:02PM (#13759972)
>At least for now, WebAssembly does not support garbage collection at all. Memory is managed manually (as it is in languages like C and C++). While this can make programming more difficult for the developer, it does also make performance more consistent.

I support anything that improves performance and efficiency. But the best of both worlds is always great. I'm wondering if it would be possible to implement reference counting (and maybe automatic reference counting) similar to Objective-C, and if so, would that simply be a matter of the particular language and WebAssembly transpiler you're using supporting it? And are there disadvantages to reference counting that make it a bad idea? I enjoyed using it doing earlier iPhone programming.

Re:What makes WebAssembly fast? by mintplant on Tuesday February 28, 2017 @08:45PM (#13760202)
GC integration is on the roadmap for WebAssembly, as I understand it. At the moment languages can bring their own GC implementations written in WebAssembly, but eventually they should be able to hook into and take advantage of the browser's native GC facilities. I believe this is considered a blocker for exposing a standard DOM API directly to WebAssembly code.
Re:What makes WebAssembly fast? by q3r3qr3q on Tuesday February 28, 2017 @08:24PM (#13760114)
> And are there disadvantages to reference counting that make it a bad idea?

I thought it had a performance cost.

Re:What makes WebAssembly fast? by ktRolster on Tuesday February 28, 2017 @09:03PM (#13760300)
Not much of one. The amount of time it takes to allocate the memory and free it is the dominant factor.
Re:What makes WebAssembly fast? by comex on Tuesday February 28, 2017 @09:13PM (#13760343)
Maybe in the non-atomic case. Atomic refcounts force synchronization between CPUs when different threads access the same data, even if they only read it; that can have a quite significant cost.
Re:What makes WebAssembly fast? by repsilat on Tuesday February 28, 2017 @10:57PM (#13760973)
They also tend to prohibit some smart gc optimisations like moving your shit while you're not looking, and the cache behaviour can be bad because either,

- the data isn't stored next to the count so you get two pointer indirection per access, or

- the data is stored next to the count, and the object gets cached-in when it gets collected.

Piggybacking on the thread because I haven't had much concrete experience with smart pointers: how does the "circular chain" problem seem to manifest? Is it

- "goes wrong quickly," usually picked up and fixed without too much trouble,

- "like any old memory leak" -- maybe a problem if processes run a long time, hard to track down, or

- devs are usually smart enough to see them coming, knowing to keep the "has a pointer to" relation a partial order (either by type or some other natural hierarchy.)

?

Re:What makes WebAssembly fast? by dalailambda on Tuesday February 28, 2017 @08:18PM (#13760083)
Since languages like Rust/C++/Swift compile reference counting into machine code already, there's no real reason why they shouldn't be able to compile it to WebAssembly.