Implement mix listener to respect concurrent compilations #5955
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This improves the code reloader to better handle concurrent compilations using Mix listeners API coming in Elixir v1.18.
The code reloader already handles concurrent compilation by checking the Elixir compiler manifest. If the manifest appears stale, we prune all modules from the given application. However, always pruning all modules can be expensive if the number of loaded modules is large.
This PR introduces a Mix listener that listens to concurrent compilations and keeps track of the changed modules. Then, before compiling, we prune only the modules that actually changed.
On Elixir < 1.18 we fall back to the current approach. On Elixir >= 1.18 we warn if the listener is not configured (and also use the fallback).
cc @josevalim