202 points · by homarp · 5y ago · 161 comments
TeaVM is primarily a JVM byte-code to JS (and WASM, and plain C code) compiler. It is so effective at this, that not long ago I was able to bring a byte-code only proprietary JVM library to the web and it just worked. This thanks to an almost complete classpath library (based on Apache Harmony) and a macro system [1] that allows to produce POJO to JSON conversion code at compile time.
I think it's interesting that they seem to position themselves as an alternative to programmers of jvm languages needing to switch to javascript for browser-side work, but they don't make a clear comparison to eg scala.js or kotlin js, where js code is generated, but not from class files.
I've tried playing with those, and one source of challenges is working with js libraries, which need some wrappers expressing method signatures, which is sometimes a challenge. TeaVM has a bunch of annotations for js interior, as well as the ability to deal with js code as just strings. But I can't see that it clearly solves the issues I find most annoying about scala.js or kotlin js. Is this only a great fit if you're in a polyglot jvm team that also wants to run that code in the browser?
These thoughts made me quit my job at Kotlin team and join Delightex to work on their product that uses TeaVM heavily: https://edu.cospaces.io/
The performance is very good (we tried other options to get a web port working before we found TeaVM, and none could compare).
The developer is responsive to bugs - but it has been rock solid for us. At this point the JS port is one of our most stable platforms.
The development environment is also nice to work with. I work with all of the native SDKs that we deploy to, and TeaVM is my favourite. In particular, the JS<->Java interop is smooth and easy with minimal boiler plate. On most platforms, using a native API is at least a little painful - with some boiler plate necessary. On TeaVM it has annotations to be able to "drop into" javascript without a lot of fuss.
I've been using kotlin-js lately for browser development (with the Fritz2 framework). It's fine and improving rapidly. Just a year ago, this would have been a bit of a rough experience doing anything with it. But I've been using it since two months and have not really encountered any major issues. The Kotlin 1.4 release really improved things. And we indeed have a lot of Kotlin code for Android and our server so that made that an easy choice for us.
It's early days for WASM and languages like Kotlin and Java but I'm guessing that a lot of stuff is going to happen there in the next years. In the end you need more than a compilation target: you also need platform integration, development tools, and libraries. Kotlin-js is getting pretty nice for each of those and with all the multiplatform stuff coming out, you don't really need or miss a lot of the npm stuff. But if you do, it's fairly easy to deal with that as well (e.g. we integrated leaflet just a few weeks ago).
WASM support in Kotlin is still pretty immature. They recently kicked off an effort to improve support for that in the multiplatform gradle plugin. But there's still a lot of work to be done there. But, long term, I'd expect to compile to that rather than to Javascript.
I do have the benefit of a UI abstraction - my UI kit runs on Swing/JavaFX on the desktop, and on HTML/DOM (canvas based) in the browser.
Some examples:
* MerchMaker (make Roblox merch): https://frequal.com/merchmaker/
* Funniest Stories Ever (fill in the blank stories): https://fse.frequal.com
* CoronaWait (store wait times and in-stock reports): https://coronawait.frequal.com/
Most anti-GC FUD regarding WASM and GC kind of stems from people not getting how GCs are implemented.
One rotten egg I can spot: "Supported subset of Jackson". Ow. Jackson is unfortunately a land mine, rattled with CVEs over the years. This was mostly fixed by taking the best ideas from Jackson and standardizing them as JsonB, which not have several good implementations. I would highly suggest they drop Jackson support in flavor of JsonB just so the Jackson libs don't have to be on anyones class path.
Have seen Jackson in parts of my code base (internal, but still)
https://www.cvedetails.com/vulnerability-list.php?vendor_id=...
As Jackson is used in Spring, you can assume most banks, big corporations, etc. use it. So, update your dependencies and it's fine.
Gson is kind of to be avoided for the simple reason that it seems to be no longer maintained by Google. I've used it in the past and its fine but wouldn't pick it for something new because of this.
If you are using Kotlin, kotlinx serialization is worth a look. I've been using that recently. One of the nice things is that it relies on compiler plugins and code generation rather than a lot of reflective magic at runtime. From a security and performance point of view, that's a good thing.
It could use some simplified syntax (similar to how Kotson improved on Gson), perhaps a JPath parser. But for something that just went 1.0 very recently, it is terrific.
Update: TeaVM does make it easier: http://teavm.org/docs/runtime/jso.html
I am guessing it will automatically look for static occurrences of park(), wait(), etc anything that goes into a blocked state and yields to the next handler on the event queue?
Even with the coroutine support, it doesn't seem smart enough to make something like "while (true) { ... }" auto-yield to other functions or handlers on the event queue. To be fair, it's not like javascript does this for you either.
Compared to React, GWT, Vaadin, and CheerpJ, TeaVM comes out on top for Lighthouse scores and JavaScript size: https://renato.athaydes.com/posts/comparing-jvm-alternatives...
The thing that is (somewhat) well-known for being an awful mess, which Google eventually realised and moved away from? Those who do not learn the mistakes of history...
* Full threading implementation
* Fast builds
* Designer-friendly HTML/CSS
Detailed comparison: https://frequal.com/TeaVM/TeaVmVsGwt.html
* TeaVM supports threads, Blazor does not.
* TeaVM apps can start in 3s, Blazor apps cannot.
* TeaVM eliminates unused code for fast startup, Blazor is architecturally limited to download an entire VM at startup.
Details: https://frequal.com/java/TeaVmVsBlazorWasm1-0.html
Comparison chart: https://frequal.com/java/TeaVmVsBlazorChart.html
A good way to think about it is a new single-page app framework for the web that lets you code in a popular, safe, statically-typed language with great IDEs and tools.
(I tend to find something HTTP-only about once a day, normally on sites that have been around for over ten years. Normally I’d just shrug if it’s a content site, but this being for making web apps, I figured it was worth commenting on.)
The only thing I can think of is my ISP injecting some HTML at the top of the page. Something that I haven’t seen for years.
Every connection that happens over unsecured HTTP is a connection that can be hijacked by middlemen for nefarious purposes, both for spying and for attacking.
Encrypting as many connections as possible is a form of herd immunity. Encrypting even unimportant "marketing" websites protects everyone on the web by raising the cost of interception and lowering the benefits.
It's also about the entire internet & its users, not just threat models on specific sites.
We can't ask the general public to consider threat models and evaluate what sites should need HTTPS or just HTTP. General, non-technical intuition is basically useless for this eval; it's not a good path.
It's much smarter to just make HTTPS the default, make it easy & free for any site to provide it, and then let browsers show big warnings for any site that's not secured.
(Browsers are moving this way already)
Yes. It's very difficult to write a full stack application using JavaScript. I cannot find tools or frameworks.
Compare: Clojure. You have the project.clj file and put your dependencies there. The you do lein run or build a fat jar and run it like java -cp your.jar your_app.core. The end.
It's worth noting that there is some inherent complexity in the web platform due to the fact that you are generally targetting multiple platforms. Server side code has it easy here (and indeed Node.js generally needs little in the way of build process)
Regarding error with native NPM dependencies (usually when switching node versionw, or switching between macOS node and linux node in docker): this can almost always be solved witha simple `npm rebuild` once when you change node version.
What would be your advice to someone seeking to do this?
e.g. - is it simply a matter of intelligence, perseverance, attitude? - is there a technical or social practice you find helpful?
Who knows what the FE team will remember to come up on the next assignment.
I come across stuff "only" using jQuery today, and every time, I end up ripping it out because it's totally unnecessary and often ends up being the source of breakage and logic errors. What's worse is that its APIs are awful, and it's impossible to debug in its blob form. The fix always ends up being to just get rid of it.
I'm hoping https://hotwire.dev/ solves some of my issues, I hope to see it picked up in SpringBoot/Quarkus community more.
Java applets involved running an actual JVM on every client computer, which meant basically doubling the risk surface of the browser... plus you had a completely different UI (that couldn't match the browser UI) sitting inside a web page.
I confess I wrote a bunch of Java applets back in the day; but I can't say I'm surprised they died, and I don't think they'll be back.
Heh. Nothing to confess. Before the HTML5 set of standards (circle 2008), there were certain things you just couldn't do in the browser with JavaScript. That's why there was space for plugins like Applets, Flash, ActiveX, RealPlayer, etc. I did quite a bit of Flash/AS3 (along with the Flash wasm/asm precursor named 'alchemy') development back in the day. If I was able to do it with JS/HTML/CSS I would have done that instead - but you just couldn't.
Java is as open source and still has multiple implementations available, even Microsoft is now a Java vendor (after having bought jClarity).
Basically you want free beer like Linux? Get a distribution from OpenJDK.
You want support Red-Hat/SuSE style? There is Oracle, and a plenty of other vendors happy to sell JDKs with support.
Java was not rescued by Oracle. There was never any danger of Java going away or not having a proper sponsor. If anything was 'rescued', it was the SPARC/Solaris division of Sun.
Java will surely live but will it thrive without all those investment?
After the Oracle lawsuit, why should people feel safe believing that Oracle will respect the terms of the license instead of trying to extract more money and subject you to a costly lawsuit?
GPL with Classpath exception covers you well enough.
Google skipped on the GPL license, so they don't get the benefits of that license.... unlike all Java users.
Java 8,11 supported by a big firm (Amazon)
The Oracle JDK is indeed free of charge for developing aplications, but running that app using Oracle Java on a server as opposed to a desktop needs a paid license subscription & generates exposure to Oracle license audits.
Many, many firms are now using OpenJDK and the like, and have policies against even downloading Oracle's version.
In short, starts at $25 per processor per month, discounts starting at 100+ . Look at using OpenJDK/ Amazon Corretto instead
Or you pay Oracle for support. Or some other company.
Oracle isn't special.
If Oracle decided to stop putting out new FOSS-licenced versions, there would be no new OpenJDK releases (since all the core Java devs are Oracle employees).
So it's like a no-community project, where you get a dump of FOSS code every now and then from a vendor.
https://blogs.oracle.com/java-platform-group/the-arrival-of-...
Oracle seems to pursue GraalVM EE as a way to monetize Java. It would be insane for them to change the license, piss off companies with deep pockets, risk a hard fork and see most employees working on the JDK leave.
And now - they can't. Companies that are able to maintain Java are X times larger than Oracle and the core team would easily be rehired by IBM, Google, Aamazon, Facebook, Apple, etc...
At the language/runtime level Java has been faster than anything else we have used on the Web with huge success (faster than PHP, Ruby/Rails, Python, Node, for example) even since 2000, and is as fast or faster than Go. It's also used in HFT - where ultimate speed means a lot.
Seriously, your argument sounds like the first year CS student argument of yore, where they hear that assembly is faster, and want to rewrite everything in assembly (fortunately today's first year CS students are more well informed).
TechEmpower benchmarks: https://www.techempower.com/benchmarks/#section=data-r19&hw=...
Language benchmarks game: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
And just because i found it pretty interesting, here's a summary of a study that not only measures memory consumption and execution time, but also how much energy certain languages required: https://jaxenter.com/energy-efficient-programming-languages-...
Sure... IntelliJ IDEA startup isn't instant. Atom's startup isn't instant. QT Creator's startup isn't instant. GIMP starts in a few seconds... etc.
* Faster startup
* Better Lighthouse score
* Less code
See for yourself: https://renato.athaydes.com/posts/comparing-jvm-alternatives...
I do sometimes use Go for its contiguous memory layout and await JEP 169: Value Objects from Project Valhalla.
Part of the problem is that those also happen to be the frameworks that the vast majority of the community uses.
The Java zealots also tend to ignore all of the problems associated with AOT Java compilers and the fact that it will most likely be a few years before value objects are finalized and in a released version of Java. Even then, a ton of Java developers won't be able to use any features beyond Java 8 or 11 since a lot of companies don't want to give up the ability to easily use their libraries on Android.