MatUrbanski
Alias vs import performance
Hello everyone. I’m pretty new to Elixir. I have question about alias and import usage. Does using import makes impact on app performance because of importing all of the code into module? When should I use import and when alias? I didn’t find any good answer for this question.
Thanks in advance.
Most Liked Responses
LostKobrakai
There absolutely is a cost to using import, because it needs to require the selected module as part of its functionality. require does cause a compile time dependency, which means both modules can no longer be compiled in parallel, but need to be compiled one after the other. The upside is that you can check at compile time if certain functions are actually defined in the external module, what you can’t do otherwise. Having a compile time dependency on a module means the current module needs to be recompiled if the module it depends on changes. So for the router helpers it at least means with each route change the compiler will need to at least recompile all the view modules.
KronicDeth
import does not “import” the code into the module’s .beam. All calls are resolved at compile time and both alias qualified calls and imported calls count as remote calls. It’s mostly a convenience for the human reader of your code.
josevalim
This is correct. Both imported and aliased calls are remote calls.








