Ensure all runtime_modules loaded before mapping their paths #12287
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.
During a typical recompilation in our codebase, we identified a long wait unaccounted for during logs emitted by
mix compile --profile time. You can see the discrepancy here:We tracked this down to
elixir/lib/elixir/lib/kernel/parallel_compiler.ex
Lines 275 to 278 in c02ea54
:code.which/1calls were taking ~25ms each because the module was not already loaded.By using the already-optimized
:code.ensure_modules_loaded/1, this change cut a huge amount of time during this pre-group-pass-check stage of the compilation process.Implementation notes:
:code.which/1gracefully filters out non-path return values, I opted to similarly not check (or log) any non-:okreturn value from:code.ensure_modules_loaded/1Miscellanea: