Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Assembly (Wasm), garbage collection

I heard Webassembly will be a compilation target for statically typed languages and can be run in the browser. Claims were made that it could run in the browser at (close to) native speed. This is because the Wasm is relatively close to the machine instructions of the appropriate machine.

However there are 2 types of languages that can compile to Wasm:

  1. Languages with garbage collection, e.g. Java, C#
  2. Languages without garbage collection, e.g. C/C++, Rust

My current understanding is that garbage collection is a process which negatively affects performance because it requires CPU cycles.

Question:

Could there be a difference in performance if a Wasm program is either written in a language which has garbage collection versus a language that has none?

like image 370
Willem van der Veen Avatar asked Sep 27 '18 18:09

Willem van der Veen


1 Answers

The GC proposal is intended to be strictly pay-as-you-go. That is, a program not making use of related instructions should not be affected in any way.

Another way to think about it, at least as far as current browser implementations of Wasm are concerned, is that the GC proposal simply gives you a way to access the same heap that JavaScript values live in. That heap exists whether or not Wasm uses it, and when it doesn't, there is no difference to the current situation.

like image 69
Andreas Rossberg Avatar answered Sep 30 '22 21:09

Andreas Rossberg