195 points · by apignotti · 3y ago · 43 comments
The paragraph with this might be a little confusing. It suggests that this is a benefit of Cheerp, but upstream LLVM (and Emscripten, which uses upstream LLVM) can do the exact same thing if you build with -flto to enable LTO.
The benefit of upstream LLVM is that it can do both LTO and non-LTO builds. Non-LTO builds link much, much faster in a large project, since the linker is only concatenating wasm object files, just like a normal linker. That can matter a lot for CI times and local debugging etc.
You can use upstream LLVM (and Emscripten, which uses it) with -flto normally on all platforms. It is basically cross-compiling, so it does not matter at all on what platform you are building, and Windows/Mac/Linux all work the same.
Just to confirm that, here is an Emscripten CI run on MacOS, where you can see among other tests ones that build with lto (search for "lto" in the "run tests" tab):
https://app.circleci.com/pipelines/github/emscripten-core/em...
Would be great to be able to sandbox x86 code trivially.
[0]: https://news.ycombinator.com/item?id=25646022 [0]: https://docs.leaningtech.com/cheerpx/
It has a permissive Apache license and numerous success stories:
https://frequal.com/TeaVM/TeaVmBasedSites.html
There is also a full SPA toolkit called Flavour Plus for making pure Java, web-native, full-stack web apps:
+ website itself is difficult to find the hello world example
+ after a long time digging one finds the hello world, but is hosted somewhere else with (again) very scarce documentation on how to get it started.
+ the number of examples on the site is 2, and only one for Java language.
Please invest more on newbie first steps. It isn't that we (end-users) are lazy, it is just that our time is precious too and this kind of information being available makes a huge difference to gain confidence into quickly grasping the basics and grow into more complex cases. This isn't possible when losing so much time around the site for info and just 1 example as showcase. (I know more examples are on github, but again had to dig to find them). Even that second link you mention has interesting examples but again, not even listed on the main page.
If you compare to similar projects like GraalVM, you can notice they include snippet examples after snippet examples for end-users to dive quick and deep on what can be done: https://www.graalvm.org/latest/reference-manual/wasm/
My apologies for the long answer. It just pains me to see a good project and a motivated person like you answering here but still with the handicap of a site that pushes end-users away.
Cheerp: A C++ Compiler for the Web - https://news.ycombinator.com/item?id=15727346 - Nov 2017 (9 comments)
Cheerp 1.2 – C++ to JavaScript: faster than Emscripten with dynamic memory - https://news.ycombinator.com/item?id=11018516 - Feb 2016 (21 comments)
Cheerp 1.1 – C++ for the Web with fast startup times, dynamic memory - https://news.ycombinator.com/item?id=10524784 - Nov 2015 (20 comments)
Cheerp – A C/C++ compiler for web applications - https://news.ycombinator.com/item?id=8167536 - Aug 2014 (49 comments)
> https://launchpad.net/~leaningtech-dev/+archive/ubuntu/cheer...
They recommend using an Ubuntu PPA with Debian? That's... definitely a bold strategy. Let's hope it works out for them.
I mean, given that they themselves suggest doing so, I take it that's the PPA has been properly tested on Debian, and that they'll answer support requests and help resolving any issues if they crop up? There aren't any Debian releases listed in the "Display sources.list entries for:" dropdown.
Hmmm....following a couple of documentation links, I get to:
https://docs.leaningtech.com/cheerp/Ubuntu-Debian-installati...
Which states "Manually edit sources.list (works on Debian testing / stretch)". Huh. testing / stretch.
Yup, I'm sure it's fiiiiine.
This is really amazing.
> The question is, what will you build with Cheerp?
I don't really know, for now all I want is executing python in the browser like brython, and see if WASM can make things better, at least give more elegant errors.
But other than that, I'd rather dump HTML as a format and have something better suited for it. I already thought about a replacement for HTML, because there are so many things to remove in HTML.
Why is that amazing? Anyone can manipulate the DOM by writing javascript.
I don't really know, for now all I want is executing python in the browser
You might want that, but do people using what you make want that? Python is already orders of magnitude slower than a native program, it's going to be even slower running in a browser.
Even things like TS still rely heavy machinery to translate ts to js.
I don't really know how TS works and if it puts the generated JS in cache.
Well brython is already quite fast already, so I don't think a WASM version would be worse.
And python performance is not such a big problem, it's up to developers to write faster programs instead by picking relevant modules and not writing low-level code. Python performance has already improved a bit, and performance is rarely a real problem in software anyway.
Python: whether you use the likes of Brython (>5MB of JavaScript, though if you’re unrealistically careful—given the choice to use Brython—you may be able to whittle it down towards 1MB) or CPython compiled to WASM (mostly even larger, but of WASM rather than JS), performance is always going to be worse than reasonably-equivalent JavaScript or ahead-of-time-compiled WASM from languages like C++ or Rust. It’s fundamentally doing more work than alternatives, so it’ll always be heavier to download, slower to run, and more memory-hungry on equivalent code. It should never be used for web frontend stuff except when operating under extraordinarily unusual constraints, because it’s simply significantly worse in every way imaginable other than “is it more like Python than like JavaScript”.
What are you basing this on? Brython's own web page says simple operations are slower than regular python and regular python is going to run at about 1/60th the speed of webasm.
Even python users seems to recommend not using it.
https://old.reddit.com/r/Python/comments/3z54u1/is_it_really...
Python performance has already improved a bit, and performance is rarely a real problem in software anyway.
Again, I think this is for users to decide if performance isn't a problem.
Most big and popular websites are sluggish even on powerful desktops, let alone a phone that's a few years old.
When someone talks about using super slow languages for something interactive and distributed to users, that's a pretty big red flag, even more when they say 'performance is rarely a problem'.
Usually, typescript is compiled to javascript in a build step (eg on the developer’s computer) using the typescript compiler. The output is javascript which can be run in the web browser directly, or bundled with webpack & friends, then loaded into the browser.
For reference, here's examples of what you could do with the baseline clang with wasm (but not JS?) [1] [2] [3], referenced from a similar thread on HN.
[1] https://github.com/ern0/howto-wasm-minimal
We do include the C (Musl) and C++ (Clang's libcxx) standard libraries.
And we do have some custom LLVM passes to improve code size and performance (See for example [1] and [2]).
But the main selling point in my opinion is the ability to target JavaScript, and (almost) freely mix data and code compiled to either JS or Wasm.
Emscripten can also target JS, but it still retains the linear memory model of Wasm (or X86, Arm, ...), which means that what you get in the end is a big TypedArray and operations on it using basic types.
With Cheerp, code compiled to JS uses an object memory model: a C++ object will become a garbage-collected JS object. While this has some limitations (you can't do unsafe casts and treat your memory like it's a big array, because it isn't), it allows seamless integration with the Browser (or any third-party) APIs:
- You can store a DOM element directly in your C++ objects (instead of doing everything through tables)
- You can directly manipulate JS Strings instead of constantly converting back and forth to C strings
- You can create nice zero-overhead interfaces to use your C++ classes from manually written JS
- Or, you can just write your whole program in C++, including callbacks for DOM events and whatnot
And you can still compile the peformance-sensitive or type-unsafe parts of your code to Wasm (losing access to some convenience in exchange for speed).
You can get an idea from the Pong tutorial [3], although it's a bit of a contrived example to showcase what can be done.
[1] https://medium.com/leaningtech/partialexecuter-reducing-weba...
[2] https://docs.leaningtech.com/cheerp/Cheerp-PreExecuter.html
[3] https://docs.leaningtech.com/cheerp/Cheerp-Tutorial-Mixed-mo...
This sounds great for ease-of-use and cross-language binding. But, there's a downside with respect to performance. With Emscripten, you never see any GC events show up in the profiler.
> Not yet. The main problem is that RuneScape requires low level network connections primitives (sockets)
So, I'm guessing the same applies to the C++ version?
[1] https://docs.leaningtech.com/cheerpj/Frequently-Asked-Questi...
https://leaningtech.com/webvm-virtual-machine-with-networkin...
Accessing DOM / external JavaScript can be done by using the __asm__ syntax while in C, use of the client namespace is only possible from C++ code
Using exclusively GPLv3 would have been better.