hst337
Tria
https://github.com/hissssst/tria
An optimizing compiler for Elixir language
Public and alpha 
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
-
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 -
Enum fusion
Join multipleEnum.maps, optimizeforloops 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
- Broad documentation (like pathex has)
- Inlining
- Hot-reloading support
- Peephole optimizations for common suboptimal code.
map.fieldhandling (did you know that it is 2-3 times slower thanMap.fetch!(map, :field)?)- 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
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 32 to 23- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mat-hek
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
What I wanted to say is that
v1.19standalone have amazing optimisations and we are talking about 3 versions in total. I believe that in this field much more happen inElixircore 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 inErlang. 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:
not in specific type of optimisation, but in total.
JSONfromv1.18standalone should be much more than enough for various big projects and we are talking about only one feature.sabiwara
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 ast = 90000, just as if it was a macro.Regarding comprehensions and the fact
Enum.mapwas faster thanforin some cases as discussed above in the thread.We did change it so it compiles as
Enum.maprather thanEnum.reducewhen it made sense (PR).Schultzer
I believe that parallel compilation and the optimizations mentioned in this thread are different.
Eiji
Looking at
GitHubrepository the last commit fixes tests forv1.15andv1.16versions ofElixirand it was send over a year ago. There is still a note warning saying thatTriais 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 thatElixircore team made various optimisations since lastTriacommit, 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
Hey, did any of this amazing work ever end up in Elixir?
hst337
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
By the way, does anyone know how to compile Elixir module without generating warnings?
hst337
I am very pleased to hear that
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
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.