Elixir 1.8 released with new features and infrastructure improvements

0
1497
3 min read

In a blog post yesterday, Elixir 1.8 was announced. It comes with a variety of infrastructure level improvements, faster compilation time, common patterns, and added features around introspection of the system. Elixir is a functional general-purpose programming language that runs on top of the Erlang virtual machine.

Custom struct inspections with Elixir 1.8

Elixir 1.8 has a derivable implementation of the Inspect protocol. This makes it simpler to filter data from existing data structures whenever they are inspected. If there is a user struct containing security and privacy sensitive information inspecting a user via inspect(user), will include all fields.

This can cause information like emails and encrypted passwords to appear in logs or error reports. Defining a custom implementation of the Inspect protocol avoided this behavior. Elixir v1.8 makes it easier by allowing users to derive the Inspect protocol. Due to this, all user structs will be printed while all remaining fields are collapsed. Passing @derive {Inspect, except: […]} will keep all fields by default and exclude only some.

Custom time zone database support

Elixir v1.8 defines a Calendar.TimeZoneDatabase behaviour that allows developers to add their own time zone databases. An explicit contract for time zone behaviours are defined, as a result, Elixir can now extend the DateTime API. This allows addition of functions like DateTime.shift_zone/3. The default time zone database in Elixir is Calendar.UTCOnlyTimeZoneDatabase which can only handle UTC.


In other Calendar related improvements, Date.day_of_year/1, Date.quarter_of_year/1, Date.year_of_era/1, and Date.day_of_era/1 are added.

Speedy compilation and performance improvements

Improvements to the compiler have been made over 2018 which makes Elixir v1.8 compile code about 5% faster. The Elixir compiler also emits more efficient code used for range checks in guards, charlists with interpolation, and when working with records via the Record module. EEx templates are also optimized and emit more compact code which also runs faster.

Better instrumentation and ownership with $callers

The Task module is a way to spawn light-weight processes to perform concurrent work. When a new process is spawned, Elixir annotates the parent process via the $ancestors key. Instrumentation tools can use this information to track the relationship between events occurring within multiple processes. But many times tracking only $ancestors is not sufficient.

Developers are recommended to start tasks under a supervisor, as it gives more visibility and control of task termination when a node shuts down. The relationship between code and the task is tracked via the $callers key present in the process dictionary. This aligns well with the existing $ancestors key. In Elixir 1.8 when a task is spawned directly from code without a supervisor, the parent process of the code will be listed under $ancestors and $callers. This feature allows instrumentation and monitoring tools to better track and relate the events in the system.

This can also be used by the Ecto Sandbox which enables developers to run concurrent test against the database. It uses transactions and an ownership mechanism in which each process explicitly gets a connection assigned to it

These were the major changes, for full list of improvements and bug fixes, you can take a look at release notes.

Read next

Elixir Basics – Foundational Steps toward Functional Programming

Erlang turns 20: Tracing the journey from Ericsson to Whatsapp

Python governance vote results are here: The steering council model is the winner