With the increasing popularity of compile-to-JavaScript languages, developers familiar with the Java Virtual Machine(JVM) languages and who want to develop web applications without the difficulties of a JavaScript development stack, have an increasing array of alternatives to JavaScript to choose from. A recently published analysis of GWT, TeaVM, JSweet, CheerpJ, and Vaadin Flow that examined performance and payload characteristics on a trivial application seems to indicate that the performance penalty vs. native JavaScript web applications is shrinking.

Java developer Renato Athaydes recently compared JVM alternatives to JavaScript. The target application that serves as reference for the comparison is a simple counter, implemented with the React JavaScript front-end library:

The counter app got implemented in five Java frameworks: GWT, TeaVM, JSweet, CheerpJ, and Vaadin Flow. The comparison between the five Java alternatives and the native JavaScript application followed a simple methodology: create the counter app using the most basic tools provided by the Java product/framework, and subsequently measure the application’s size, and performance. The application size is obtained through the browser’s network tab (counting all types of resources to avoid bias in favor of frameworks that rely on heavy, non-JavaScript resources). The performance is measured leveraging the auditing tool from Google Chrome’s built-in Lighthouse. LightHouse's performance score is evaluated on six weighted metrics, presented here in decreasing order of importance: Time to Interactive, Speed Index, First Contentful Paint, First CPU Idle, First Meaningful Paint and Estimated Input Latency.

The study shows that JSweet and TeaVM beat the native JavaScript React application on the First Contentful Paint(FCP) measure as reported by Lighthouse. Google reports that First Contentful Paint "measures the time from navigation to the time when the browser renders the first bit of content from the DOM. This is an important milestone for users because it provides feedback that the page is actually loading". While most implementations obtain what is deemed by LightHouse to be a good global performance score (> 90 with a maximum of 100), the CheerPJ framework performed poorly in comparison to its peers.

The resulting Java framework ranking can be explained in large part by the size of the produced JavaScript:

Here, the Java frameworks rank in the same order. This is to be expected, as the time for the browser to parse the produced JavaScript correlates positively to size and negatively to performance.

The study does not include J2CL, a recent google-backed Java-to-JavaScript transpiler. Furthermore, the study relies on a trivial web application. While the results cannot be extrapolated to a large web application, it serves nonetheless to analyze the differences between the Java frameworks considered in the study.

CheerPJ's large size and subsequent poor performance can for instance be explained by the fact that it is not really a Java-to-JavaScript transpiler but a complete Java runtime shipped to the browser. On the bright side, CheerPJ allows developers to take a compiled jar containing a Swing app and run it in the browser, without plugins.

GWT (released in 2006) is a mature open-source technology used for instance by Google AdWords. GWT ships with a series of widgets and panels for user interface construction.

TeaVM claims to be an ahead-of-time compiler for Java bytecode that emits JavaScript and WebAssembly that runs in a browser. TeaVM does not require source code, only compiled class files. Moreover, the source code is not required to be Java, so TeaVM may compile Kotlin and Scala.

Jsweet self-describes as a transpiler from Java to TypeScript/JavaScript with 1000+ well-typed JavaScript libraries available from Java. Jsweet claims to allow developers to access generated APIs/objects from JavaScript, without requiring additional tooling or runtime. However, Jsweet does not fully emulate Java. Existing Java applications may have to be modified in some measure, in particular those which use Java-specific APIs such as Swing for the user interface.

Vaadin Flow is a set of components and tools for building web apps in Java. Vaadin Flow features built-in Spring support, automatic server-client communication with WebSocket support. Web applications may be written in pure Java, or a mix of Java and HTML. Vaadin's components are web components self-described as mobile-first, fine-tuned for UX, performance, and accessibility. However, Vaddin Flows ships a client-side engine weighing over "300k compressed (regardless of app size)". The latter explains the performance profile of Vaadin Flow.

The study methodology is inspired from the blog post A real-world comparison of front-end frameworks, which InfoQ previously reported on.