MatUrbanski
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.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
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
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 11 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
Ok, TIL. My bad
josevalim
This is correct. Both imported and aliased calls are remote calls.
NobbZ
importandaliasdo not change if a function call is remote or local…Will both result in BEAM bytecode roughly equivalent to the following and therefore be remote calls:
gregvaughn
Is that true? I always thought
importjust did a compile time check for the functions’ existence, but still generated the remote call AST.christhekeele
That’s a good point, I forget that local vs remote calls have slightly different hot-code-reloading characteristics, and
importvsaliasdetermines if they are local or remote.I’d be curious to see what the performance diff between the two is, even though it’s totally negligible to every application I can conceive of. I did some digging around the core erlang docs and BEAM internals book and there are slightly different instruction sets for them, but I couldn’t divine what the end cost to the caller would be.
At any rate, it’s the lowest level of perf difference possible above the bytecode level, so whichever produces the most maintainable code for one’s situation is to be preferred for sure!
hauleth
I am not so sure. IIRC
imported functions aren’t remotely called, which mean that if you overwrite imported module in the runtime then the module will still use old implementations.aliaswill make calls remote, so there will be negligible performance hit, but it will provide more flexibility.christhekeele
Important to emphasize: this only introduces perf penalties during compilation. By default that is only once each time you deploy to production, and every time you change files in a dev environment.
Your original question asks if this affects app performance, which for most app production deployment techniques means only runtime perf, not compile time perf. In this case there is no impact.
Kurisu
Thank you for this clarification. ^^
LostKobrakai
There absolutely is a cost to using
import, because it needs torequirethe selected module as part of its functionality.requiredoes 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.Kurisu
After reading this about upgrading to Phoenix 1.4:
Should we consider that there is at least a compile-time performance matter between
aliasandimport?I found this topic because I was wondering if I will import back the router helpers in my phoenix project as before
1.4 version…