-New in elixir 2023
Introduction
Elixir enthusiasts and developers, rejoice! Elixir v1.15.0 has arrived, and it brings a slew of exciting improvements that promise to elevate your coding experience. This latest release focuses primarily on enhancing compilation and boot times, making your projects more efficient and ready for production.
Moreover, Elixir v1.15.0 completes its integration with the Erlang/OTP logger, introducing features like log rotation and compression. In this article, we'll delve into the key features and enhancements offered by Elixir v1.15.0, helping you harness its full potential.
Compile and Boot-Time Improvements
One of the standout features of Elixir v1.15.0 is the significant reduction in compilation time. In previous versions, the code path accumulated entries for every application and dependency in your project, resulting in slower compilation as your project grew.
However, with this release, Elixir introduces code path pruning, ensuring that only the entries listed as dependencies are included.
This optimization aligns compilation behavior more closely with 'mix release.' Additionally, Elixir v1.15.0 leverages Erlang/OTP 26 capabilities to start applications concurrently and cache code path lookups, leading to faster boot times. Whether you're launching 'iex -S mix' or running tests, you can expect a noticeable reduction in application startup times.
As an illustration, benchmarking the Livebook application on a M1 Max MacStudio with approximately 200 source '.ex' files and 35 dependencies showed a 16% improvement in compilation times and a 30% boost in boot times.
While the exact results may vary depending on your specific project, it's safe to say that the more dependencies and files you have, the more you'll benefit from these improvements.
Some users have even reported up to 40% faster compilation times, although the generalizability of such results may require further exploration. It's worth noting that these enhancements primarily focus on optimizing the compilation of project-level dependencies and not individual file compilation.
Furthermore, the compiler itself has become smarter in various ways. '@behaviour' declarations no longer introduce compile-time dependencies, and aliases used in patterns and guards no longer add any dependencies, as there's no dispatching involved.
Mix now tracks the digests of '@external_resource' files, reducing recompilation when switching branches. Additionally, Elixir v1.15.0 offers automatic recompilation of dependencies when their compile-time configuration changes, ensuring a seamless development experience.
Potential Incompatibilities
It's crucial to be aware of potential incompatibilities that may arise due to the code path pruning introduced in Elixir v1.15.0. If you have an application or dependency that doesn't specify its dependencies on Erlang/OTP and core Elixir applications, you may encounter compilation issues. While you can temporarily disable code path pruning by setting 'prune_code_paths: false' in your 'mix.exs' file, doing so may lead to runtime bugs that manifest only in 'mix release.'
Compiler Warnings and Errors
Elixir v1.15.0 takes a step further in improving the developer experience by introducing the ability to emit multiple errors for a single file. This enhancement ensures that developers receive more comprehensive feedback before compilation is halted. In previous versions, an undefined function would be reported as
However, in Elixir v1.15.0, the new reports will appear as:
To support this, a new function called 'Code.with_diagnostics/2' has been introduced, allowing editors to point out several errors at once. Ongoing work is underway to further enhance the compiler diagnostics in future Elixir releases.
Integration with Erlang/OTP Logger
Elixir v1.15.0 introduces seamless integration with Erlang/OTP logger, offering global logger metadata and file logging with rotation and compression right out of the box. This release soft-deprecates Elixir's Logger Backends in favor of Erlang's Logger handlers.
Elixir will automatically convert your existing ':console' backend configuration to the new format, simplifying the transition. For example, the previous configuration:
Now translates to:
You can even replace the default console handler with one that writes to a file, offering log rotation and compression options, as follows:
The previous Logger Backends API is now soft-deprecated, and if you've implemented your backends, you should consider migrating to ':logger_backends' for long-term compatibility.
Conclusion
Elixir v1.15.0 is a testament to the Elixir community's dedication to making the language faster, more efficient, and developer-friendly. This release is a game-changer for Elixir developers with improved compilation and boot times, enhanced compiler diagnostics, and seamless integration with the Erlang/OTP logger. Whether you're starting a new project or upgrading an existing one, Elixir v1.15.0 promises to streamline your development process and boost your productivity.
To learn more about the complete list of changes, refer to the [full release notes].