-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Demo crashes from high memory usage #4
Comments
Thanks for the report @guest271314! Briefly Googling the message I think I hit the same error you did in my Linux VM. Once I gave the machine more RAM it worked on Chromium 89: Can you confirm if giving the browser more memory fixes the issue? I know that's not ideal, but it would be good to confirm the cause. |
I am not sure what you mean by giving the browser more memory? I can run BleachBit to clean memory. If the user is running entirely on RAM it is probably not possible to add more RAM dynamically after startup. I do not know Go and not completely sure how you have set this up, though at Chromium we can write directly to the local filesystem using File System Access API (Native File System). I have used |
Yeah, that's the idea. In my case I had to close Chromium's other windows to reclaim enough raw memory on the machine so it would launch. Fully understand the frustration there though. I have experimented with using IndexedDB as a way to move the file system onto disk, but I hit several issues I haven't been able to solve on my own. You're welcome to try it out, though. The IndexedDB adapter is still wired in, just not enabled by default (due to various hangs and crashes in the WASM implementation).
That sounds great! I'm not familiar with the API yet, but that could be a good solution. We may need to give IndexedDB another shot first, since it's more widely supported at the moment, but I've been keeping an eye on Chromium's newer file API. It looks promising for sure! |
If you're interested in hacking on go-wasm, I'd be happy to give you some pointers! Notably, the indexeddb package is the current experimental implementation. It's wired in using mountfs. You can actually mount it from JS in the demo too, using |
At Chromium or Chrome File System Access API (formerly native File System) provides a means to write directly to local filesystem. I have not tried IndexedDB. I do not want the browser having any control over what I write, and AFAICT IndexedDB is under the influence of memory and hard disk quotas, similar to On the path you on currently on relevant to session and local storage @fivedots have done and are doing with NativeIO, see WICG/storage-foundation-api-explainer#4, https://github.com/fivedots/nativeio-porting-tutorial. I do not get frustrated. I create workarounds. Mission statement: Fix
I am interested in reading and writing to and from STDIN and STDOUT. I do not have a use for IndexedDB or NativeIO or other browser-backed private origin (sandboxed) filesystems (we can get and change the data anyway if we really want to https://stackoverflow.com/a/36098618). Yes. I am interested in learning. Where to begin? All I know about Python I learned over the past few weeks experimenting with the sample sample code from https://github.com/GoogleChrome/samples/blob/gh-pages/quictransport/quic_transport_server.py using the now obsolete |
@JohnStarich What interests me in your work is that you compiled Go to WASM
One project that I have not completed is porting |
Yes, great points. I've looked briefly at the Chrome File System Access API. My impression is it would be a great integration, but it looked experimental to me? If it looks like it will hit stable eventually, I think that's a good fit for go wasm 👍 The initial reason I started with IndexedDB is because it offered a rich API for large blobs of arbitrary data, without a huge performance penalty. Currently I'm hitting issues with the transactions not starting because they're waiting for the scheduler to move on, but Go sits there waiting on the result (even though it was started in a Promise 🤷). I did take a stab at local / session storage too, so that could be an option as well. I appreciate the links! I'll have to take a look at these projects, very interesting indeed.
Fair 🙂 My most constrained resource is time, so any of these options could be great – just have to find the time to work on them!
Your use case sounds solid to me. Once we can figure out how to move the Go installation out of RAM or add some other form of caching, then you should be good to go. (If you do want to take a shot at solving these memory problems, just let me know.) |
Still experimental. I am not sure if shipped by default now with a flag necessary. The tracking bug should have information on the current status. Some issues are the necessity to read the entire file when reading and writing WICG/file-system-access#157, https://bugs.chromium.org/p/chromium/issues/detail?id=1084880
Have you experimented with
flags.
That would be useful. Yes. I have largely solved the issue that began this process by creating virtual devices that I can access via A TODO is to write a "circular" or "ring" buffer so that we can write to the same memory location once we reach the end of the designated memory instead of just allocating N amount up front https://github.com/guest271314/webtransport/blob/main/webTransportAudioWorkletWebAssemblyMemoryGrow.js#L13. That is, allocate, e.g., 3 seconds of data, when we read that last 128 bytes for |
Thank you for your encouragement 😄 Nice! Glad you got past your issue 👏 I've had an epiphany. (I swear the longer I stare at something the less it makes sense, but in this case it helped. 😝) Classic rookie mistake, I ran WASM function calls on the main thread as part of my debugging steps. Unfortunately, IndexedDB requires transactions to complete on a follow-up run loop – so running WASM funcs that wait on the FS in the main thread blocks and crashes the program. Turned out the IDB file system is working quite well, which is nice. I made some progress with memory reduction via the go build cache: The first profile was the "before" and the second is "after", showing only adding an IDB FS for the go-build cache shaved off It definitely slowed down time-wise, so that'll need to be optimized at some point too. |
That is still a substantial amount of computing resources used. When running a live session could cause a crash. Native Messaging and |
Agreed, it is substantial. It can be significantly reduced with this IDB FS, just need time to work out the details. There’s some nuance for how WASM is handling shared data in memory, so much of the data is being duplicated as it’s being loaded and stored. I hear you on native file access helping out, and that could be quite useful. My understanding is that it’s still experimental and only offered by Chromium though. I’m focusing on a cross-browser and cross-platform solution at the moment, to improve the overall experience. Once RAM and task completion times are more reasonable, then I can look at adding that feature too. (And, of course, PRs are welcome if you’re just itching to do it now.) |
Native Messaging is supported at Chromium and Firefox browsers. File System Access API is a relatively new and different API. With Native MEssaging you can post messages to and from a native application, e.g., see https://github.com/guest271314/native-messaging-espeak-ng where |
Aha, I totally missed the whole Native Messaging idea in there, my bad. So you're interested in making your native app available to a Go program in go-wasm on stdin/stdout via That sure sounds amazing. My only question is, does it have to be in a browser extension to access those native message APIs? The docs seem to lean that way, but I'm not familiar enough with the API. |
I filed this Chrome feature request https://bugs.chromium.org/p/chromium/issues/detail?id=1115640 for the ability to write to a Native Messaging provides a means to execute arbitrary code and get output using text messages. I achieve the requirements of capturing system and specific audio output using Native Messaging first, which necessitated several steps, then tried the same approach using the deprecated What I am attempting to convey is that I filed this bug because you embedded Go in WASM. At the time I was trying to embed |
Sweet, I hope it goes through. I imagine security will be pretty important in nailing that idea down. For Update on reducing memory usage: I've got the page using barely above 250 MB now, on my local copy. I've even reduced the memory usage during compilation to nominal levels. All "disk" access slowed waaaaay down, so I'm working on that piece now. Startup times of 5 minutes are less than ideal 😉 On the bright side, after the cache is populated, the startup time is near-instant. Also now Safari is able to run go-wasm without immediately crashing due to memory usage. |
For testing, yes. The server can be remote, https://w3c.github.io/webtransport/#dom-webtransport-webtransport-url-options-url.
That can still be prohibitive when running a live OS on RAM.
For example, if you already have Go installed on your machine, there is no need to use WASM at all to run Go from the brower. It should also be possible to create the server with Go, and other programming languages installed, e.g., Try It Online https://tio.run/#, if the application requires Web request, and not the installed code, again, without potentially creating a duplicate install of WASM code in RAM. |
@guest271314 Agreed on memory usage still being high. There will need to be further optimizations in the future, since my time is limited. I've also spoken with @fivedots, so I'll be giving I've wrapped up the current changes to enable persistence and (slightly) lower memory usage 🎉
This is certainly interesting, I'll need to give it further thought. Ultimately, if it over-complicates the user experience then I may need to leave it out. I don't know many people that would be willing to configure experimental features for a browser-based IDE. But hey, I could be totally wrong! 🙂 |
Check this out https://blog.stackblitz.com/posts/introducing-webcontainers/
|
@JohnStarich FWIW a proof of concept of what I was trying to achieve when I filed this issue https://github.com/guest271314/NativeTransferableStreams. |
@guest271314 That's awesome! Thanks for sharing! Looks like they've managed to get a networking stack working, but also quite a lot of press and funding around the project. I'm curious how they're handling non-native modules, or if that's even supported at the moment. 🤔 Lots to think about. |
Congrats! I may take a look around, seems like a cool project too. |
The demo eventually crashes at Chromium 89

The text was updated successfully, but these errors were encountered: