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
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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.
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…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
Thank you for this clarification. ^^
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.
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
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!
gregvaughn
Is that true? I always thought
importjust did a compile time check for the functions’ existence, but still generated the remote call AST.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:
josevalim
This is correct. Both imported and aliased calls are remote calls.