Mojo Build size

Why mojo builds have such a size? Even simple Hello World programs have around 4 mb sizes. I first thought it might me my issue but the guy on this video also faced with it: https://www.youtube.com/watch?v=Bt3BVjW8FoY Compared to C builds, it's a lot. Isn't this an issue for a system programming language?
Coding with Mat
YouTube
Trying out Mojo - Is it Fast?
🚀 Ayo! I've been hearning a lot about this new "sonic" programming language that's (mostly) compatible with Python: Mojo - But are the rumours true? 🖥️ Today we'll try out the Mojo programming language and it's SDK to compare how writing code in yet another programming language feels. In addition, we'll also judge it's build system and how eas...
9 Replies
Darkmatter
Darkmatter5w ago
I have a feeling they bundle some level of debug symbols. I’m not near a computer with a Mojo install but I think that if you strip the binary the size will go down quite a bit. The mojo stdlib also has a few bits of code that may not be removed if not needed for various reasons. Rust has the same thing with large default binary sizes and it just takes a little effort to knock it down to C level because it automatically builds with things you need to ask a C compiler for like debug info, some types of linking information, etc. Also, keep in mind that an install of python is >200 MBs which is what Mojo is really aiming for. I routinely see my venvs get above 2 GB because python can’t tree shake at all.
DobyDabaDu
DobyDabaDu5w ago
Hmmm, I see. Didn't know about Rust. Thank you for your explanation!
Helehex
Helehex5w ago
Last time I checked the sizes were pretty small
DobyDabaDu
DobyDabaDu5w ago
My builds with 24.4 stable are still the same. U can check them here: https://github.com/yetalit/Mojo-journey/tree/main Maybe nightly builds became small...
GitHub
GitHub - yetalit/Mojo-journey: My journey with Mojo programming lan...
My journey with Mojo programming language. Contribute to yetalit/Mojo-journey development by creating an account on GitHub.
bpr
bpr5w ago
Running strip on Ubuntu takes the size of the Mojo "hello world" executable from 4MB to 350K. For comparison, a C version is 16K and a Rust version built with the "--release" flag is 390K on my machine, and strips down to 327K.
Darkmatter
Darkmatter5w ago
If you follow everything in min-sized Rust, you can get Rust to C size. C is small because it's dynamically linking a 2.4 MB dependency (at least on my fedora). I had assumed that everyone was comparing to statically linked C using musl or similar, but if you link dynamically of course it will be smaller, you are choosing to sacrifice performace for disk space.
bpr
bpr5w ago
Right, I should have left the C out of the comparison as it was misleading. In any case, the stripped Mojo is close enough to the stripped Rust that I wouldn't sweat the size. I hope that future versions of "mojo build" will provide optimization flags that will allow us to make tradeoffs, but the biggest size one here is, as you said, dynamic vs static linking.
Darkmatter
Darkmatter5w ago
You actually get to around the dynamically linked C size if you follow the min sized Rust rabbit hole before you even need to toss std, for a statically linked executable. The issue is that core::fmt has a lot of machinery it drags in that println!("Hello World") doesn't actually need. Also, even a 4/8 MB binary is nothing compared to what Python has, so I think it's a non-issue for the main place where people care about binary size, docker containers, because you don't need to include a whole unnecessary Mojo runtime whereas the CPython runtime is ~260 MB with the main binary alone.
Helehex
Helehex5w ago
the sdl-bindings package me and ryulord have been working on only has a 1mb package size im on nightly though same with infrared, ~1mb and i didnt do anything fancy to them maybe there was an oversight on the last stable causing larger packages or something
Want results from more Discord servers?
Add your server