News

Elixir 1.8 released with new features and infrastructure improvements

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

Prasad Ramesh

Data science enthusiast. Cycling, music, food, movies. Likes FPS and strategy games.

Share
Published by
Prasad Ramesh

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago