Follow us
Breaking
Product Reviews

Gleam v1.11.0 increases JavaScript performance

Gleam v1.11.0 delivers a 30% speed increase for code compiled to JavaScript, specifically boosting Lustre framework performance. Testing shows HTML table diffing operations rose from 142,000 to 208,000 per second in the latest version.

Share

Gleam v1.11.0 provides a 30% speed increase for code compiled to JavaScript. This update specifically improves the performance of the Lustre frontend web framework, which uses a virtual DOM implementation for both single-page applications and LiveView-style functionality. Developers measured the performance gain by testing how many operations per second the framework performs when diffing HTML tables of various sizes. For a 10-row table, version 1.10.0 performed 142,000 operations per second, while version 1.11.0 increased that number to 208,000 operations per second. This improvement occurs because the Gleam compiler produces JavaScript code that resembles what a human developer would write manually. The Gleam team does not add any additional runtime to the generated JavaScript.

Metric Version 1.10.0 Version 1.11.0
10-row HTML table diffing (ops/sec) 142,000 208,000

The Gleam compiler itself is written in Rust. Since the language reached version 1.0 in March 2024, the team has maintained a stability commitment. The community also focuses on the developer experience, as the language server provides useful code generation.

Type-safe wrappers and typeclasses

The Gleam type system catches errors during compilation, which prevents null pointer exceptions and errors where a value is undefined. Typeclasses provide a way to automate semantic operations like summing values or ordering data when using nested wrappers. A developer might wrap a numeric value in a Money type, then wrap that in a Dollar type, and finally place it in a Balance type to manage specific amounts. If the developer needs to sort a list of these Balances, they must write a custom function to compare Balances, which in turn requires a function to compare the underlying Dollars, creating a repetitive cycle of manual implementation. Without typeclasses, a developer faces a significant burden because they must write custom functions for every level of the data structure to handle iteration and comparison.

This automation works regardless of the order in which the developer creates the data structure, provided each part remains marked as comparable. This efficiency extends to third-party types, such as a Wallet, because the developer only defines the comparison implementation once for the outer wrapper. The compiler then handles the rest of the hierarchy. This also applies to JSON serialization. In a complex structure of lists and objects, the compiler only needs to know how to serialize each component individually. If any part of the structure lacks serialization capabilities, the compiler notifies the developer.

BEAM interoperability and the Elixir debate

Gleam targets the Erlang Virtual Machine and JavaScript runtimes, which allows developers to write code for both the backend and the frontend using the same language. While most basic language features function identically on both platforms, users must use Erlang FFI for BEAM-specific tasks like OTP and JS FFI for JavaScript-specific tasks. Gleam developers can access all existing Erlang and Elixir OTP modules, although the Gleam team provides a specific set of modules to ensure type safety for certain OTP functions. These Gleam-specific modules do not yet support all system messages or named processes, though the team plans to add named process support in a future release.

You might find the differences in philosophy between Gleam and Elixir striking, especially since the Gleam developer survey indicates that most Gleam programmers do not use Elixir. Elixir provides a highly dynamic approach to solving problems, whereas Gleam emphasizes simplicity and tight static analysis. Some users view Gleam as similar to Elm because it prioritizes safety and a small, intentional design. While Gleam provides the Wisp framework for backend development and Lustre for frontend development, it does not offer OTP support out of the box. Users must instead use a separate package to implement OTP functionality. All three languages, including Erlang, Elixir, and Gleam, implement OTP in user land rather than having it as a core language feature. The language also includes the echo keyword, which has been reserved since version 1.0 to provide stack information. Will Gleam eventually provide native support for all OTP system messages?

Share

Technewsdaily

Senior tech writer covering AI, gadgets and cybersecurity. Breaking down the news that matters, every day.