winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.73k stars 185 forks source link

Playground: WASM Out of memory #2869

Closed skorfmann closed 11 months ago

skorfmann commented 1 year ago

I tried this:

Open more than 5 tabs of the playground with this link

Screenshot 2023-06-09 at 17 33 44

This happened:

The sixth tab threw an error

Uncaught (in promise) RangeError: WebAssembly.instantiate(): Out of memory: Cannot allocate Wasm memory for new instance

Subsequent new tabs were stuck in loading mode. Screenshot 2023-06-09 at 17 43 40

Screenshot 2023-06-09 at 17 45 33

I expected this:

Is there a workaround?

Don't open too many tabs (or buy more memory?) :)

Component

Playground

Wing Version

0.19.6

Wing Console Version

No response

Node.js Version

?

Platform(s)

MacOS

Anything else?

Notes:

While the first occurrence of this happened in a browser session with plenty of tabs, I was able to reproduce this with a fresh Chrome instance.

Each new tab seems to consumer 900 MB - 1 GB

Screenshot 2023-06-09 at 21 33 14 Screenshot 2023-06-09 at 21 33 41 Screenshot 2023-06-09 at 21 34 06

Here's the related Slack thread

Community Notes

Definition of Done

Implementation notes

skorfmann commented 1 year ago

There seems to be a 4GB memory limit for WASM in Chrome https://chat.openai.com/share/eae464a8-ecdd-4fd9-abca-6ba55916f626 (which is confirmed by https://v8.dev/blog/4gb-wasm-memory). However, this is per WASM instance according to ChatGPT, not sure how trustworthy that info is though 😆

ainvoner commented 1 year ago

@ekeren let's priorities

ekeren commented 1 year ago

@eladcon , as we use the playground more, it is becoming an issue.

can you take a look?

ekeren commented 1 year ago

Noticed this

https://blog.stackblitz.com/posts/debugging-v8-webassembly/

ekeren commented 1 year ago

It happens to me on the forth tab

image

eladcon commented 12 months ago

seems like this is a websontainer issue. even when not running the console at all and just installing the dependencies (running npm install i can only open 6 tabs. using wing wasm outside of webcontainers works fine (the lsp is working even with 20 open tabs)

ekeren commented 12 months ago

Checked with @eladcon

Even when you open https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-tvjtvf?file=README.md 3 times, it stops working with the same issue

ekeren commented 12 months ago

updated definition of done of the ticket

skyrpex commented 11 months ago

I got an idea to overcome this issue. As far as my experiments go, the memory is allocated per domain (eg: play.winglang.io vs learn.winglang.io).

If we instantiate the webcontainer in random subdomains such as abc-123.play.winglang.io, we can open any number of apps. So, play.winglang.io would use an iframe to random-345.play.winglang.io. The users shouldn't notice a thing.

eladcon commented 11 months ago

i think it would work, though we would need to manage those domains

ekeren commented 11 months ago

Great idea. What do we need to serve from these subdomain?

We can have a wildcard subdomain going to the same location

ShaiBer commented 11 months ago

Do we still need to solve this problem if we go with the backend solution?

ekeren commented 11 months ago

I think that util we know that the backend solution is solid, we should treat it as a P2.

I want to be risk averse at this point in time

ShaiBer commented 11 months ago

👍

skyrpex commented 11 months ago

So I tried going forward with my tests using dynamic subdomains such as abc123.play-test.winglang.io, def456.play-test.winglang.io, etc, inside an iframe published in play-test.winglang.io.

There's a problem and is that the WASM files are being loaded in the topmost frame on the browser tab, which would be play-test.winglang.io, so it works the same unless we make our users open the playground using the subdomain URLs directly.

As @ainvoner mentioned, we prefer to receive traffic to from winglang.io directly so using subdomains isn't a viable option, but what if we do the following?

We can enable tab to tab communication between subdomains, so technically it isn't a problem.

ShaiBer commented 11 months ago

Sounds reasonable to me

ekeren commented 11 months ago

@skyrpex , this should be for learn as well