When I import a library in elm, will importing only specific functions be more efficient than exposing everything ?
For example, when I import the Html module I usually just expose everything
import Html exposing (..)
This is convenient so as i keep writing I don't have to keep modifying the definition to add more Html tags, but is it efficient ? Will the compiler realize I don't need the entire library in my source code or will it import it all ?
I don't think there is a performance advantage in importing exactly the functions that you want to use. As farmio mentioned, before 0.19 the whole module is imported anyway and after 0.19 you can pass --optimize
to eliminate dead code.
However, I strongly recommend against importing all the functions exposed by a module because it makes code very hard to read. Imagine this case:
import Html exposing (..)
import Svg exposing (..)
import Html.Attributes exposing (..)
import Svg.Attributes exposing (..)
We have pulled all the functions from those four modules into our own namespace, so everytime I read the name of a function which is not defined I have to guess where that function is coming from. The alternative is just exposing types but never functions:
import Html exposing (Html)
import Svg exposing (Svg)
import Html.Attributes as HAttr
import Svg.Attributes as SAttr
In this way, not once you will have to guess where the function is coming from.