![]() |
|
![]() |
| It's a bit easier to do when you don't limit yourself to exactly 80-char per line
|
![]() |
| It'd be fun/great if someone made Graal Native work with it. Then things could come full circle and I could compile my Clojure/Java binaries to run everywhere (but now without a VM) |
![]() |
| You're basically just benchmarking the WIN32 filesystem versus a Linux VM in that case. The Windows file system is famously slow. It'd make more sense to compare a Cosmo binary running on WIN32 with a WIN32 native program. For example, Emacs has a WIN32 port where they wrote all the Windows polyfills on their own, and because they aren't experts on Windows, the official GNU Emacs Windows releases go a lot slower on Windows than if you just compile Emacs from source on Linux using Cosmo and scp the the binary over to run on Windows. See https://justine.lol/cosmo3/
|
![]() |
| Cosmo author here. We used to build our code with musl-cross-make. Once Cosmopolitan got good enough that we could compile GCC using Cosmo, our build latency dropped in half. https://x.com/JustineTunney/status/1726141024597324189
Cosmopolitan Libc is 2x faster than Musl Libc for many CLI programs like GNU Make and GCC because it has vectorized string libraries like strlen(). Musl won't merge support it on x86. I even mailed Rich patches for it years ago. Cosmopolitan's malloc() function is very fast. If you link pthread_create() then it'll create a dlmalloc arena for each core dispatched by sched_getcpu(). If you don't use threads then it'll use a single dlmalloc arena without any locking or rdtscp overhead. Cosmo has pretty good thread support in general, plus little known synchronization primitives from Mike Burrows. You can do things like build a number crunching program with OpenMP and it'll actually run on MacOS and Windows. Cosmopolitan plays an important role in helping to enable the fastest AI software on CPUs. For example, Mozilla started an open source project called LLaMAfile a few months ago, which runs LLMs locally. It's based off the famous llama.cpp codebase. The main thing Mozilla did differently was they adopted Cosmopolitan Libc as its C library, which made it easy for us to obtain a 4x performance advantage. https://justine.lol/matmul/ I'm actually giving a talk about it this week in San Francisco. |
![]() |
| I'm always somewhat scared - not sure if rationally or irrationally - about cosmopolitan.
It's a cool hack but I somehow feel like it should not work. |
![]() |
| Cosmo author here. Could you please clarify what specific object file features we're abusing? The only hacky thing I did was remove the shebang line, and POSIX was awesome enough to change their rules to let us do it. https://austingroupbugs.net/view.php?id=1250 Beyond that, we just depend on stable ABIs and APIs. We don't link NTDLL for example. It's just straight up WIN32. On MacOS ARM we use the dynamic linker. I want Cosmo programs to stand the test of time. That's why I stopped building apps with NodeJS and wrote this instead. The whole reason this release is on the HN front page, is probably because it got rid of MAP_FIXED mappings and page size assumptions. So if you can tell me where we're still exposed, then I'd love to fix it. Thanks!
|
![]() |
| > I disagree with your assessment in all cases. You simply do not know what you were talking about.
No need to be rude. > Standardization efforts and backward compatibility assumes a well-behaved application. If you explicitly depend on really weird hacky stuff like abusing corner cases in the object file format, you risk breakage and you will break. Sure, but if you get the standard to include your use then it's not a hacky edge case anymore. Ex. https://justine.lol/cosmo3/ "POSIX even changed their rules about binary in shell scripts specifically to let us do it" > https://austingroupbugs.net/view.php?id=1250 |
![]() |
| It’s quite rare to ship multi-Unix binaries, isn’t it?
Cosmopolitan is a very cool hack indeed, but IMHO it’s not likely to gain widespread usage. |
![]() |
| It doesn't really work, the libc is widely non-conforming.
I'd rather have a proper interface designed for portability rather than a hacked-together POSIX-but-not-really. |
![]() |
| From here: https://github.com/jart/cosmopolitan/releases/tag/3.5.0
Justine wrote:
What is the motivation behind this? Try to reduce (compiled) binary size? Naively, I am surprised that the C++ STL from Clang isn't OK to use, including the license. Or is this a clean room impl thing?EDIT To be clear: I mean no disrespect with this question. This is an amazing project. EDIT 2 Ok, I just spotted this commit message: https://github.com/jart/cosmopolitan/commit/c4c812c15445f5c3...
template library compatible APIs while compiling 10x faster than libcxx.Can someone explain to an average C++ programmer like me how they make it compile 10x faster !? |
![]() |
| The rationale is explained in this README [1], but it basically boils down to transitive dependencies and the amount of checks the compiler has to do. From linked README:
"If we `#include [1]: https://github.com/jart/cosmopolitan/blob/master/ctl/README.... |
![]() |
| Is there a plan to distribute the cosmopolitan libc without all the APE stuff?
For now it seems to be more like a framework+toolchain than a standalone library. |
![]() |
| quickjs [1] has native support for Cosmopolitan, is meant to be easily embeddable, and is included as part of the standard Cosmopolitan distribution. It looks like qjs also has patches for recent-ish versions of the Typescript compiler as well. Someone has made a nodejs-style project called txiki.js [2] using vanilla qjs. Maybe it would build with Cosmopolitan with some tweaking. But if you're thinking of packaging a whole browser engine like Electron that might be a Sisyphian effort.
[1] https://bellard.org/quickjs/ [2] https://github.com/saghul/txiki.js/ |
![]() |
| I wonder if it is possible to have a 100% portable qemu build with this. Would be funny to have a usb stick with qemu + VM that runs on any OS. |
![]() |
| in release note:
> ... , it reconfigures stock GCC and Clang to output a POSIX-approved polyglot format ... Did POSIX really _approve_ this? if yes, when? |
![]() |
| Cosmo author here. I'm familiar with the new rules. They were first implemented in https://github.com/freebsd/freebsd-src/commit/e0f5c1387df23c... which makes a clear intentional allowance for what APE is doing. If you look at the hex dump:
You'll notice there's no NUL characters on the first line, and that the subsequent NULs are escaped by a single-quoted string, which is legal. The rules used to be more restrictive but they relaxed the requirements specifically so I could work on APE. Jilles Tjoelker is one of the heroes who made that possible. |
![]() |
| Any idea if there will ever be a fix for the majority of linux distributions that cannot run cosmopolitan C applications without the bin fmt fix? |
![]() |
| wouldn't targeting webassembly provide something similiar? how would this compare to targeting WASM and running a runtime like wasmer? |
![]() |
| WebAssembly is bytecode that runs on a virtual machine.
Cosmopolitan is a libc replacement. Your program is still compiled to real CPU instructions, which execute much faster. |
![]() |
| It works on AMD64 and ARM64 both.
It makes two architecture fat binary, but removes all code not needed. Resulting binary is typically only 30-50% larger than 1-architecture binary. |
![]() |
| Is that an embedded device with a small address space? APE used to require a 47bit address space. The release I published today fixes that. Maybe give it another try? |
![]() |
| Looks like there is both an ARM and x86 version according to the docs. Probably need two different binaries, but you still get cross-OS for each architecture. |
![]() |
| It's a single binary, cross-OS, cross-arch.
Go to https://cosmo.zip/pub/cosmos/bin/ and download an executable, like https://cosmo.zip/pub/cosmos/bin/basename .
On macOS with an M1:
On FreeBSD with an amd64:
|
I enjoyed the video. However, both the author and Donald Keith strike as two people who are mainly motivated by aesthetics (which is supremely ironic as they almost define themselves as being the opposite of Loren Ipsum). I like people who deliver results.
I think the author mostly likes the appearance of someone who pays attention to detail. He says that in a movie if it's obvious that the coffee cups are empty, he notices and bothers him. 3 minutes later in his video he has a guy using his laptop at the beach where glare would make it impossible to see anything on the screen.