
Up to 4GB of Memory in WebAssembly - feross
https://v8.dev/blog/4gb-wasm-memory
======
xscott
I wish new platforms would embrace 64 bit as the default. C and C++ for all
common platforms use 32 bit literals and prefer 32 bit operations (char *
short => int). Rust made a similar mistake. Java arrays use 32 bit subscripts,
etc... I don't have a single computer (including my phone) using 32 bit
pointers, but integers are stuck in the late 80s. (We already had 64 bit DEC
alphas in the early 90s)

For a web page, 4 gig seems like a courtesy limitation to users, but that
should be enforced by the browser refusing to suck up the entire computer
rather than the language being unable to. I routinely write (non-web)
applications which use arrays larger than 4 gigasamples.

~~~
gpm
I, on the other hand, wish everyone would embrace 32 bit by default. Doubling
the size of every index, integer, etc comes at significant memory cost for
next to no benefit. Increasing the amount of memory used directly impacts
performance considering how slow memory is and how important it is to keep
commonly used items in cache.

If you're seriously using more than 4gb in a web page... I wouldn't mind a
non-default wasm64 format. You should also be considering shipping a native
app at that point, wasm is not free in terms of performance.

~~~
centimeter
> Doubling the size of every index, integer, etc comes at significant memory
> cost for next to no benefit.

The _overwhelming_ majority of GUI program data is composed of images,
textures, sounds, videos, 3D models, text, etc.

I would bet that less than 5% of the memory required to host a popular web
page (facebook, amazon, etc.) is dedicated to pointers, array indices, etc.

~~~
gpm
The overwhelming majority of what wasm will be used for probably does not
include images, textures, sounds, videos or 3d models. The overwhelming
majority of the memory in most wasm programs will probably be not large arrays
of text.

The webpage as a whole is a gui program, but wasm is primarily a place to run
computationally intensive code. The web-browser deals with things like
rendering images natively without storing the image in wasm.

~~~
monocasa
What do you think that computationally expensive code is cranking on? It ain't
small bits of text.

~~~
gpm
When it is text, it's usually more small bits of text than big bits. If you're
just copying around giant strings you're unlikely to be using webasm. More
likely you're copying around tons of small strings as you format them into a
giant string if that's the end goal. Or you're copying around tons of small
strings as you use those small strings to make api calls to the dom
(indirectly through js). Or you're just plain running something like a physics
simulation and don't even have text in the first place.

------
greatgib
It's like reinventing what exists and doing the same mistakes that were
already done!

------
_bxg1
Just reading the part about the ensuing JavaScript implications gave me a
stress-headache. Bless the people who are willing to work through these kinds
of issues so the rest of us get to use the result.

------
juntao
V8 wasm has memory size limitation because it is fundamentally limited by the
chrome browser.

But other server-side WebAssembly don't have this question, for example, SSVM
never had any arbitrary memory limit.

------
rajsite
Does the 4GB limit only apply per WebAssembly instance or does it apply to the
V8 runtime as a whole? Can a single page run multiple separate 4GB WASM
instances?

------
baybal2
So, will we need to have 4GB of ram to run Javascripts now? :)

~~~
orangepanda
The title refers to web assembly memory limit. However, it’s mentioned
javascript now supports up to 16 million terabytes of memory (equivalent to 4
jira tabs).

~~~
eggsnbacon1
Hah! It really is comical how insanely slow and bloated JIRA is. Its the only
tab I keep open 24/7 because loading it takes so long.

When I restart my PC I have a login script that fires up a bunch of slow stuff
while I get coffee. My IDE's, Docker containers... and my JIRA tab :)

------
sparsely
Imagine how much adware you'll be able to fit in 4GB!

------
pan69
Are WebAssembly projects going to display a message somewhere that says
"WEB4G" when started?

(disclaimer: If you're under 35 you might not get this reference)

~~~
recursive
I'm 39 and I don't get it.

~~~
hed
I assume it's from when you used to boot DOS mode games that addressed beyond
640KB conventional memory they had DOS/4GW labeled all over.

[https://en.wikipedia.org/wiki/DOS/4G](https://en.wikipedia.org/wiki/DOS/4G)

~~~
recursive
The slash helps. I'm pretty sure Duke Nukem, Doom, and similar all showed that
banner during startup.

~~~
pan69
Yeah, sorry. Forgot the slash. It's only been 20 to 25 years... :)

------
MaxKK
Amazing that they have a dark mode detection on that website.

~~~
TeMPOraL
You can do that in CSS now. I've noticed surprisingly many sites adjusting
when I started using a Windows machine and set my system-wide preference to
dark mode.

~~~
diffrinse
Prolly cause the devs themselves use it

~~~
aledalgrande
Yup I try to convert every product I develop lol

------
Ericson2314
Why do we need to support stating the length ~~"2^32+1"~~ 2^32?

~~~
wahern
It would be "2^32", not "2^32+1". 2^32 isn't representable in a 32-bit
integer, the same way 256 isn't representable in an 8-bit integer--the maximum
is 2^8-1, or 255.

But the argument that they need to represent 2^32 and therefore _that 's_ why
they used 64-bit integers is dubious. No 32-bit WebAssembly program could ever
operate on and pass an object as large as 2^32 bytes because the code and data
structures for the smallest possible program would already take up more than 1
byte in that 32-bit address space.

~~~
snek
As is mentioned in the article, u64 was used to future proof for wasm's
upcoming memory64 type:
[https://github.com/WebAssembly/memory64/blob/master/proposal...](https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md)

~~~
Ericson2314
Yeah, so what are they going to do when they then claim to need to to
represent the length 2^64?

~~~
Dylan16807
That won't happen on a 64 bit machine. By the time we need that, the code will
be so vastly different that trying to prepare for it now would be
counterproductive.

~~~
Ericson2314
I agree it's stupid. I think worrying about representing the length of 1
object filling the entire address space is stupid, wether the address space is
2^32 or 2^64

~~~
Dylan16807
> representing the length of 1 object filling the entire address space

Isn't this about encoding the WASM address space itself, inside the outer
computer's 64 bit address space?

It's only a slight annoyance if it doesn't get to be quite the normal limit,
but since they're changing some of this code anyway, and they're going to need
even bigger numbers in the future, it makes sense to do a proper adaptation.

