Skip to content
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

How small can I get this? #16

Open
wormyrocks opened this issue May 29, 2024 · 4 comments
Open

How small can I get this? #16

wormyrocks opened this issue May 29, 2024 · 4 comments

Comments

@wormyrocks
Copy link

Hopefully should be reasonable simple to answer -
I'm trying to build a proof-of-concept hardware demo that implements a mass storage device with a portable OpenSCAD compiler. No UI, fonts, etc., are required, just a single .HTML file where you open it, click a button, and it spits out an STL from a hardcoded SCAD model. Since I'm not assuming the presence of a web server, I can't fetch OpenSCAD from a CDN because of CORS policy, and anyway I want it to work offline.
My target for the entire package is 2 megabytes, as that's the size of the NOR flash I built the hardware with.
I see that openscad.wasm can LZMA compress down to 1.7 MBytes, and I imagine there's some way to unpack that blob on page load. So it all seems possible. But I'd like a bit more headroom.
What are the build-time flags I should be switching off to get the size down even further?

@t-paul
Copy link
Member

t-paul commented May 29, 2024

I'm not aware of any easy wins. What might make a difference is telling the compiler to optimize for size, but I don't know how well that is supported for WASM and it's quite some work to get that into the whole build process including all the libraries.

@DSchroer
Copy link
Collaborator

For this since its all in existing hardware, how come you need to use wasm and web vs directly compiling OpenSCAD for the platform? Wouldn't you be able to achieve much better performance and size characteristics?

@wormyrocks
Copy link
Author

wormyrocks commented May 30, 2024

OpenSCAD doesn't need to, and can't, run on the hardware (it's a 50 cent microcontroller), but the hardware does generate SCAD data, and enumerates itself as a USB mass storage device.
We could just directly serve .scad files, but I thought it would be snazzier to serve a static, offline webapp that embeds the generated data along with an OpenSCAD compiler, then spits out meshes on demand. The micro is not powerful enough to generate meshes on its own.
FWIW, if I lzma-compress the .wasm file, then base64 it, I end up with a 2.3MB JSON string, which I assume can be bodged into the rollup configuration somehow... so I'm within spitting distance. And wasm-opt -Oz is able to knock about 100K off the .wasm file.

@DSchroer
Copy link
Collaborator

I see. Sorry I assumed the device needed to run it not just serve it. I guess you could try building your own version with a different set of compiler flags to try and squeeze a bit out. I'm assuming that you are using a fixed .scad file so you could even go so far as try to strip out features that your file does not use and rebuild the wasm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants