Is there a guide about how to use HIPE in elixir?

I have some questions about this:

  • Is everything compiled and ran by mix already using hipe, after running iex I see that hipe shows on the message

Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.2) - press Ctrl+C to exit (type h() ENTER for help)

  • How can I compile only an specific module in erlang I can add the attribute module -compile()

  • Is there a guide about when we should use HIPE and how to use it on elixir?


You use hipe exactly the same way you do it in erlang - with a module attribute. The syntax in elixir is @compile .... The hipe bit in the VM manifest is merely stating that this VM has support for hipe-compiled programs.

Hipe doesn’t work too good if you have a code that switches often between hipe and non-hipe code - the switches are expensive.


I never used HiPE per module attribute in erlang, but using {erl_opts, [{native, o3}]} in my rebar.config.

So could you please provide a full example of how to activate HiPE for a single module, and for the complete project as well?


Check this chapter

1 Like

There is an ElixirSips video showing how to use HiPE


For the record, you can set the env-var ERLC_COMPILER_OPTIONS with options to be passed to erlc when compiling Erlang and Elixir code (because Elixir code gets translated to Erlang).


e…g. to compile only your deps native:

ERL_COMPILER_OPTIONS="native" mix deps.compile

You know it’s working if compiling takes much longer!


Not accurate here…

The correct is:

Both Elixir and Erlang are compiled to same byte code.

No, actually Elixir does output to Erlang code. Erlang Core it might do later, but for now it is still outputting to Erlang itself for a variety of extra ‘free’ compiler checks it gets.

Thanks for the clarification @OvermindDL1 and sorry @ellispritchard for my wrong correction.

This was caused by reading somewhere, more than once, that Elixir was compiled to the same byte code of Erlang, not translated to Erlang code.

Trying to find that sources led me to this article and for what I can understand Elixir is not translated to true Erlang code as some Erlang developer would write, but instead is translated to an Erlang Abstract Format to take advantage of the mentioned BEAM optimisations.

I was not able to find the sources of my misunderstood but at least I know more about what is the compiler process now :slight_smile:

1 Like

From my understanding it does output to Erlang itself, not Erlang Core, I know that translating to a lower level was eventually planned (and the new debug segments added to the BEAM facilitate making that easier), but I don’t think it’s been done yet? Would love to find out though. :slight_smile:

Well from the blog post I linked it does look like so…

Maybe I am still misunderstanding something?


Hmm, it’s possible it does use the EAF, I’ve always dumped out Erlang Core when I want to see what it is making so that is above that…

The primary reason to use Erlang Abstract Format instead of Core Erlang is tooling. Using that we get, basically for free dialyzer, cover, debugger and erl_eval. Compiling to Core is also a bit awkward since it’s a moving target - it’s treated as an internal detail of the Erlang compiler and changing rather frequently between releases.