hst337

hst337

Tria

https://github.com/hissssst/tria

An optimizing compiler for Elixir language

Public and alpha :tada:

I’ve made this repository public to finally get some rest and find other developers who may be interested in participating in this project (it sounds so naive when I write it) before getting hands on the second iteration.

Current state

!!!Unstable!!!

Tria passes most of the tests in Phoenix, Ecto, Plug and other projects, while it may fail to compile other projects. You’re welcome to compile projects using Tria and fill an issue if something fails. This kind of help would be heavily appreciated.

Even without considering this, Tria compiler lacks some important features like incremental compilation, warning handling and stuff.

However, you can expect the stable version during 2023-ish

Current features

  1. Compile-time evaluation.
    Yes, as simple as it sounds, Elixir and Erlang were incapable of doing this, since they support runtime recompilation. Ahead-of-time nature of Tria allowed to evaluate pure statement in compile time

  2. Enum fusion
    Join multiple Enum.maps, optimize for loops to finally be efficient and other magic.

I haven’t benchmarked these yet, but these optimizations actually work and (more importantly) work correctly in most cases

Planned features

  1. Broad documentation (like pathex has)
  2. Inlining
  3. Hot-reloading support
  4. Peephole optimizations for common suboptimal code.
  5. map.field handling (did you know that it is 2-3 times slower than Map.fetch!(map, :field)?)
  6. Type-checker integration

Help wanted

If you’re interested in optimizing compiler development, you’re welcome to take a look around, poke some things, check some stuff. I know that some Brazilian universities are working in Elixir-related compiler development, and I hope we can collaborate on Tria someday

PS: Questions are appreciated


UPD: License is going to change in a near future

Showing Posts 32 to 23

mat-hek

mat-hek

Membrane Core Team

I believe most of these optimisations could be applied in the Erlang compiler (that Elixir uses underneath) and in the BEAM, not in the Elixir core. Haven’t heard of them being introduced, unfortunately, but maybe I missed something.

Eiji

Eiji

What I wanted to say is that v1.19 standalone have amazing optimisations and we are talking about 3 versions in total. I believe that in this field much more happen in Elixir core than this project offers. I’m not even sure if this package works without any problems on latest versions. Look how much changes was made also in Erlang. That’s why I believe that just being up-to-date is not only more stable, but most probably also much faster option.

It’s like:

v1.19 standalone > v1.16 with Tria > v1.16 standalone

not in specific type of optimisation, but in total. JSON from v1.18 standalone should be much more than enough for various big projects and we are talking about only one feature.

sabiwara

sabiwara

Elixir Core Team

Not directly although some elements of the discussions have actually been implemented to some extent.

We did move some pure function evaluations to compile-time, see Inline functions in Elixir -> Erlang pass · Issue #13475 · elixir-lang/elixir · GitHub.
So for instance, if you write t = to_timeout(hour: 1, minute: 30), it will be compiled as t = 90000, just as if it was a macro.

Regarding comprehensions and the fact Enum.map was faster than for in some cases as discussed above in the thread.
We did change it so it compiles as Enum.map rather than Enum.reduce when it made sense (PR).

Schultzer

Schultzer

I believe that parallel compilation and the optimizations mentioned in this thread are different.

  • const evaluation.
  • module inlining (AFAIK, BEAM can’t cross module inline functions).
  • fused enum.
Eiji

Eiji

Looking at GitHub repository the last commit fixes tests for v1.15 and v1.16 versions of Elixir and it was send over a year ago. There is still a note warning saying that Tria is unstable and may break a code. Regardless if it works or not it’s most likely not a good idea to use it anywhere close to production and I believe that Elixir core team made various optimisations since last Tria commit, so we either way would not feel much change especially if we have enabled parallel compilation in latest release candidate which is truly amazing.

Schultzer

Schultzer

Hey, did any of this amazing work ever end up in Elixir?

hst337

hst337 OP

:tada: Incremental compilation is ready

If you’re interested, you can try using Tria during development. Plus it is now completely safe to use Tria alongside vanilla elixir compiler

hst337

hst337 OP

By the way, does anyone know how to compile Elixir module without generating warnings?

hst337

hst337 OP

I am very pleased to hear that :heart:

That’s might be true, since this is the first iteration of compiler and I’ve implemented just some basic optimizations so far. You can expect something benchmarkable after the second iteration.

And, as far as I know, membrane’s code is already idiomatic and performance-tuned, so there is almost no space for current low-hanging-fruit optimizations I’ve implemented.

Yes, that’s true, right now Tria compiles whole project into single module. This approach insignificantly reduces function call overhead and gives more space for Erlang’s inlining optimization pass.

I’ve already implemented some logic which allows to compile Tria into several combined modules (instead of big and huge one)

hst337

hst337 OP

I think the most important thing here is change its behaviour. Some tests may only check if something was called and what arguments were passed to it.

Right now Tria is incompatible with Patch. But I don’t know what Jose’s plans about inlining and compile time evaluation are.

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
rodloboz
I’ve started working on a new library to run SQL queries and do basic business intelligence. Think “Blazer for Elixir.” Currently it fe...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
CodeSync
:microphone: ElixirConf 2026 - Call for Talks is open! We’re heading to Chicago :united_states: :round_pushpin: In person + virtual :d...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews