TeaVM: Build Fast, Modern Web Apps in Java
teavm.org
teavm.org
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.
So between a CPU and VM depends pretty much on how one looks at it.
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)
In many countries MITMing your page and replacing its contents, or using it to serve malware to targets is a frequent case.
What is the ISP injecting into page?
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.
https://nextjs.org/case-studies/hulu
https://nextjs.org/showcase/uber
https://eng.lyft.com/changing-lanes-how-lyft-is-migrating-10...
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.
And "lolz"? 2010 called...
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.
FYI: The point is that every year or two you get a new "revolutionary" framework. Unless you're working full time on FE - you're not going to be "in with the cool kids".
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?
So what? What does that have to do with what I argued?
>Java will surely live but will it thrive without all those investment?
Are you really trying to make the argument that had Oracle not bought Sun, that Java, one of the most popular programming languages, would have gone away?
>as proven by the high performance JIT and GC implementation available for Ruby and Python by the community.
It's almost like interpreted dynamic languages are not quite as conducive to the same kind of optimizations as a statically typed compiled language. JavaScript, another interpreted dynamic language, did have massive amount of resources poured into its JIT and GC implementation. No question there were meaningful performance gains. Is it faster than Java? No. Is it ever going to be faster? No, not unless the language compromises on its dynamic nature.
And you're still chasing this red-herring. I never argued that FOSS can do a better job at evolving a programming language runtime, than a corporate sponsor. Why are you harping on that as if that is an argument to support the idea that java was in trouble and needed a bailout from Oracle?
Are you actually making the argument that had Oracle not bought Sun that Java, one of the most widely used commercial programming language then and now, would have .. what? Gone away? Disappeared?
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.
Google had the opportunity to own Java, decided it wasn't worth the money, so now they should suffer the long due penalty.
If a company has the option between OpenJDK and its "free" license or paying Oracle for a different license, why would anyone feel safe choosing the former, given that when you deal with Oracle, you deal with the risk of wasting as much money or more to defend yourself in court than the price of Oracle's paid option? Open source licenses are only as good as as the belief by the licensing party that the terms of the license mean anything.
If you don't want to give money to Oracle, there are plenty of other companies to choose from, including Amazon, IBM, Microsoft, Alibaba, SAP, Azul.
You listed OpenJDK as a viable "free" option. Defend it, or don't, but stop trying to pivot the conversation while pretending that changing the subject is a valid answer answer to the thing that was asked.
Your favourite search engine has the answer.
If you feel like trolling, that is your problem, bye.
Facts: We have evidence that Oracle doesn't care about the actual terms of GPL. We have evidence that they're willing to subject people to legal turmoil if Oracle decides they want you to pay instead of using the "free" license.
> Defend it, or don't, but stop trying to pivot the conversation while pretending that changing the subject is a valid answer answer to the thing that was asked.
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.
Have to check your link to find out, but is it by number or by impact?
(Asking cause many projects have seemingly many "external contributors" but if one looks almost all real work happens by a core team, and the external contributors just do some change here and there, or even clerical work, like fixing comments and documentation and such).
> Of the 2,136 JIRA issues marked as fixed in Java 15, 1,702 were completed by people working for Oracle, while 434 were contributed by individual developers and developers working for other organizations.
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...
> Companies that are able to maintain Java are X times larger than Oracle
With exception of maybe IBM which anyway is crapping out, none of the other owe their business success to directly to Java based product or services. If Java were to be abandoned they can easily migrate / rewrite their internal tools / products to a different platform even if it takes 5-10 years. It is not like current prod systems will stop working just by announcement.
Also to think further Oracle abandons Java , Amazon and Google would have huge incentive to either charge lot more for Java on cloud or redirect their customers to alternatives.
They had the opportunity to do so for at least a decade now, but they didn't. Google, even after the massive row with Oracle, still uses Java extensively. Still has new projects written in Java(or running on JVM). Having a big legal battle between Google and Oracle would surely have dissuaded FAANGs from starting Java projects, right? Nope... You're flat out wrong.
> Java were to be abandoned they can easily migrate / rewrite
That's one delusional world you live in.
> It is not like current prod systems will stop working just by announcement.
And what makes you think that those big boys aren't going to be interested in maintaining JVM?
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-...
Lambda instances run really well with JVMs(the whole COW memory architecture)... and even CLIs run well enough.
I actually like Java and the JVM but if AOT compilation and efficient memory usage is what you want Java is definitely not the language to use.
They try to paint an extremely rosy picture of the current situation when the reality is that it's a very long way from the experience you get in Rust, Go, D, C, C++, Haskell, Ocaml or any of the languages where AOT is considered the default.
Any sufficiently large population will have someone who will literally say anything. And the common outrage trope on the internet is to rage against a straw man.
Now I haven't used GraalVM in production, but in having played around with it and doing new code from scratch, I found AOT compilation to be really good.
I think the change will come faster than you think.
You can build your leaf, domain level code into a native shared lib and still use the reflective code at the top level to compose the application.
https://www.graalvm.org/reference-manual/native-image/#build...
If Java gets CTFE (compile time function evaluation), constexpr for C++ folks, much of the need for runtime reflection would disappear.
There is no reason that JITed reflective code (along with VM) can't be combined AOT code in the same program. You can already do this in Graal via front ends for llvm-ir and wasm.
As it is now, you can already mix Rust, C, C++ trivially with bytecode via LLVM ir. And for languages that compile to Wasm, GraalVM has a front end for that as well.
https://www.graalvm.org/reference-manual/wasm/#embedding-web...
Just to remind people that Quarkus has a "pre-compile" stage that allows code to wire itself up using reflection, annotations, config properties, etc, before the full compile. This makes start-up times much faster.
Quarkus, Redhat's, native first frameworks works fine with Hibernate and GraalVM. One of contributors gave a [talk](https://www.youtube.com/watch?v=za5CSBX-UME&feature=youtu.be)
Plus not everyone is fan of Spring and Hirbenate.
The first I used only once in 20 years of Java projects, the second is the first to go away when I get called to optimise database performance in Java applications.
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.
However, it's all besides the point because this tool takes Java (JVM) bytecode and translates it to WebAssembly, there's no JVM involved for end users at any point.
* 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.