stackblitz / webcontainer-core

Dev environments. In your web app.
https://webcontainers.io
MIT License
3.7k stars 139 forks source link

First WebContainer call is slow #1138

Open privatenumber opened 11 months ago

privatenumber commented 11 months ago

Description of Bug

Provide a concise description of your bug and your project link (if applicable). https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-j1y8jn?file=main.js

When I call mkdir right after WebContainer boot, it takes about ~3,700ms to make a directory. The second mkdir takes 1ms.

I think this is happening because the WC is busy during startup. If it is, I'd like to be able to wait on that, either by including it in boot() or a separate Promise, so I can display a loading state.

Steps to Reproduce

https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-j1y8jn?file=main.js

Expected Behavior

Screenshots/Screencast

Additional Context/Questions In my app, it looks like mkdir project; cd project; npm install xyz is slow because it takes extra long when executing it immediately on startup but you can tell it's not running yet because there's no stdout. I have a separate loading state for WC booting and I'd like for that to be more accurate.

privatenumber commented 11 months ago

Not sure if anything was done but noticing an improvement:

Screenshot 2023-07-28 at 10 10 56 AM
SamVerschueren commented 11 months ago

We are always trying to improve the performance over time. I don't think we did something specifically on this one. The 2s you saw on your initial example is very slow though. Not sure what went on there.

It is true that after webcontainer.boot() is called, there might still be some things starting up.

We're currently actively working at improving startup times and what not. So I hope we can share some news on that soon.