Replies: 3 comments
-
I've elected to use the last alternative method of source inclusion with core as a runtime dependency on the server side. A directory is created inside the system's temporary folder in order to extract the embedded sources (which, in this example, is everything inside the Here is some sample code to that effect. This is server-side code where the ui sources are embedded. Output:
Code:
it works surprisingly fast. |
Beta Was this translation helpful? Give feedback.
-
@0pcom Thank you for asking about this. In our case, we use GitHub Pages to host all of our apps statically; see https://github.com/cogentcore/core/blob/main/.github/workflows/core.yml and https://github.com/cogentcore/cogent/blob/main/.github/workflows/core.yml for examples. That allows us to take advantage of GitHub features while not bloating the repository with any large files, as everything is done in the GitHub Workflow, so the binary doesn't get checked into the repository. In your case, if you already have a server that you need for other reasons, then you probably want to compile the binary when you first start up the server, as it seems like you have done. That is similar to the GitHub Workflow approach in that you are programmatically compiling the code on the server side, which avoids the need to include it in the Git repo, and you don't need to compile it manually. Reducing the binary size on web is an ongoing process. The biggest thing will be #974 if possible, but GopherJS is too far behind on versions to use yet. We are changing the font embedding process in #1457, which should reduce web binary size by around 6%. We will also improve icon embedding in #1473, which will further reduce the binary size of some apps. We experimented with UPX and wasm-opt before and found similar unsuccessful things as you. However, gzip does do a great job with wasm files in general, and all of our apps are served with gzip compression automatically done by GitHub pages. You can also set the Overall, it seems like you have found a reasonable solution, and it is not clear what else we can do at this point until GopherJS is ready. If you have any other questions or ideas, I would be glad to hear them. |
Beta Was this translation helpful? Give feedback.
-
Yes, in my case I need a server which is looking at files on the disk (which are updated by another process) that will serve the wasm as well as other endpoints for the wasm running in the browser to communicate with the server and get the updated data. This is for one user interface among several that the software has, and the others are embedded. The size of this is, I think, somewhat critical if the compiled web UI is to be embedded. In my case, golang + core as a runtime dependency for compiling the UI was an acceptable compromise for the much smaller size of embedding the uncompiled source code - because this particular UI is something only developers run, currently. But for any truly distributable software, you would not want to have golang as a runtime dependency if you could avoid it, because sometimes only very old versions of golang are available on, for instance, armbian & other .deb based distros, and upgrading to sid to be able to get a recent enough version of golang is time consuming and resource intensive. So sometimes you just have to bite the bullet and embed the compiled wasm. I mainly share this for the benefit of others and my own future reference. And that's great to know about the gzip flag. Core is such an impressive framework that it tempts inclusion of multiple different UIs (desktop & web) in a single application. |
Beta Was this translation helpful? Give feedback.
-
Concept: embedded wasm
The idea is to be able to embed the web sources compiled by
core build web
into another golang program - presumably the server side part of the same application.The main motivation for doing this is file size limit for files uploaded to a git repo.
I see, now, that the file size limit is much lower for uploading files via the github web interface than via
git add
on the command line.However, it is still beneficial to include the smallest binary possible in a git repo if that is being embedded into another golang program and served.
I've never come across a tool which can successfully compress a wasm binary - but I've not done an exhaustive search.
UPX
I can confirm from previous tests that UPX is not suitable for compressing wasm binaries, and will not produce a working wasm binary.
binaryen
It seems that
wasm-opt
provided by binaryen may function correctly for compressing wasm binaries. I'm compiling it now to test....
After installing binaryen I attempted to run the
wasm-opt
tool on the compiled app.wasm of the web sources for docswith the most aggressive mode, I was running out of RAM before the operation completed. It consumed ~13GB of ram
Here are other optimization options from
wasm-opt
With
-O2
the binary size shrinks by only a few megs, but the operation does complete.With every setting above
-O2
I had to kill the process at around 90% memory usage. Perhaps it will work better on a machine with more RAM,Compression to transfer encoding formats
Instead of compressing the wasm binary such that it maintains execute-ability, perhaps it could be compressed via brotli or gzip or other browser supported compression formats. The reasoning for this is that one isn't typically executing the wasm binary on the disk. The browser gets them via network interface, so it's potentially a little tweak on the server side of just setting the compression type while not applying compression for the already-compressed wasm binary. The advantage of this is that it can possibly be coupled with other binary compression methods which result in executable wasm files.
Source inclusion +
core
compiler as runtime dependencyAn alternative approach - assuming that I want to run an application with
go run
orgo install
- without having the sourcewould be to include (embed) the golang source code which is compiled by
core build web
into the server side of the application. Then, one can invoke the program to produce the files on the disk which are then compiled bycore build web
and served by this application. This would certainly avoid bloating a git repo with a wasm binary, but it would add the core tool (and golang) as a dependency for at least the subcommand which invokes this.The advantage here is just avoiding a wasm binary in a git repo for application source code.
Beta Was this translation helpful? Give feedback.
All reactions