warmwaffles

warmwaffles

What are some strategies to make Dialyzer run faster?

We have a rather large code base ~2200 elixir files and growing. On my nice Ryzen 9, it takes ~47 seconds to analyze the generated PLT files. Our config looks like this:

  defp dialyzer(env) do
    [
      plt_add_apps: [:mix, :ex_unit],
      flags: ~w(
        error_handling
        extra_return
        missing_return
      )a,
      plt_file: {:no_warn, "priv/plts/dialyzer-#{env}.plt"},
      list_unused_filters: true
    ]
  end

In our CI environment, dialyzer is taking ~2 minutes. I blame the underlying server equipment here, but locally this is painfully slow to run and to build the PLTs take even longer than our test suite does to run. (14,000+ tests ~100 seconds).

What are some strategies that others have employed to speed this up or help the dialyzer along? One mentioned was to avoid opaque types.

Most Liked

christhekeele

christhekeele

You can build just the PLTs without doing analysis via dialyzer --plt. I work this into my cache system (varies by CI provider) with a cache key based on elixir + erlang versions and a hash of mix.lock; so PLTs only build when any of those change. This amortizes your PLT build times over just commits that would require rebuilding PLTs by busting the cache.

Generally,

  1. Try to restore PLT cache based on language/library versions
  2. Build the PLTs on cache miss
  3. Run dialyzer normally using cached/newly built PLTs

Steps 1 and 3 are fast and the happy path. In practice this looks like (for Github-flavored CI):

- name: Restore mix typecheck cache
  id: mix-typecheck-cache
  uses: actions/cache@v4
  with:
    path: priv/plts
    key: plts-otp-${{ steps.beam-versions.outputs.otp-version }}-elixir-${{ steps.beam-versions.outputs.elixir-version }}-mix-lock-file-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Setup typechecking
  if: steps.mix-typecheck-cache.outputs.cache-hit != 'true'
  run: mix dialyzer --plt --format dialyxir

- name: Run typecheck tasks
  run: mix dialyzer --format dialyxir
warmwaffles

warmwaffles

Yea we definitely cache the PLTs prior, but the cache is busted if mix lock is changed.

warmwaffles

warmwaffles

Unfortunately we have ~181 dependencies and we do bump deps frequently. I should also mention that the caching also is calculated based on tool-version, all the config files (we have conditional compilation yay), and this mix lock.

Where Next?

Popular in Discussions Top

AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31695 143
New
jer
I’ve been using umbrellas for a while, and generally started off (on greenfield projects at least) by isolating subapps based on clearly ...
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 14350 124
New
thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement