GusGA
Difference between in load a large array string from a config file and load from a module
I forked an elixir lib that generates heroku random names.
On the “master” repo, the nouns and the adjectives are loaded from a config file. I change it, I create a module from each one, one for the nouns and one for the adjectives.
Now, Which is the benefit or difference from load it from a config file or a module?
Thanks in advance.
Most Liked
idi527
![]()
Load from config = lookup in an ets table. To compare ets lookup with a module lookup, we’d need to know how exactly the latter happens. I’ve seen some people putting data in maps and then just calling Map.get on it like
defmodule SomeModule do
@data %{
a: 1,
b: 2
}
def lookup(key) do
Map.get(@data, key)
end
end
which would mean that the difference is the same as ets vs maps.
The other way I’ve seen people use is utilizing constant pools:
defmodule SomeModule do
data = %{
a: 1,
b: 2
}
for {k, v} <- data do
def lookup(unquote(k)), do: unquote(v)
end
def lookup(_not_found), do: nil
end
You can learn more about it from the discordapp/fastglobal readme. It’s always been faster in my experience than the map approach above. This was also the approach I used (without any dependencies though) when I needed something like heroku random name generator as well, mostly because it was more readable than the other approaches I could think about.
Last Post!
GusGA
Popular in Questions
Other popular topics
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









