Description
One difference compiling to JS vs WasmGC is that when we compile to WasmGC we currently always box integers when they flow in top types. This has the consequence that when one uses integers in lists, maps, json, etc we may have to allocate lots of objects (which is slow & memory hungry).
(We have added some workarounds here e.g. in the json decoder where we have a pre-allocated list of integer boxes for very small integers)
We could switch to using i31ref
as top type. That would allow representing small integers without object allocations, matching what happens in dart2js. The consequence will be that certain operations will get slower (or larger in size): Loading class id from a top type has to check for i31 (this affects dispatches on selectors of Object
such as toString()
/ hashCode
...), downcasts of receivers (possibly the same size, but slower in runtime as JS runtime will have to perform the integer/reference check), ...
See also related #52714 that would workaround this issue List<int>
specifically via custom list implementations.