Start-time optimizations#11326
Conversation
If the kernel crashes during boot, it is useful to load a couple of text formatting modules so that we can print a nice crash message. As the kernel (and by extention code_server) is terminating we can get into races where the error_handler sees the code_server, but it is gone when it tries to call it. So we add a fallback to init if that happens.
This function allows other processes to do parellel loading with init which is usefull before the code server has been started.
We preload all modules used when boot the kernel in order to do it in parallel. We don't want to load any modules that we later don't use, so there are now tests that make sure that only the minimal set of modules are loaded. This is done in order to speed up boot time.
Preload modules used by the parser and compiler so that we get parallel load. Add tests to make sure that we load exactly the modules that we need.
CT Test Results 7 files 615 suites 3h 22m 21s ⏱️ For more details on these failures, see this check. Results for commit b124845. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
|
Each start script has a list of modules that will be loaded in parallel by otp/lib/sasl/src/systools_make.erl Lines 1541 to 1577 in 51a9da0 That list of modules were last updated in 2018. Perhaps you could update that list to be the minimum set of modules that will always/almost always be needed and add a test case to ensure that it remains up-to-date. |
Yes, that is part of this PR already. |
This PR optimizes the startup time of init, kernel and escripts by keeping a minimal list of modules that are used during boot and loading those in parallel before they are used. Doing this reduces startup time by 7-25% depending on scenario.
The escripts just call
erlang:halt/0directly inmain/1.Measured on my M5 Mac.
While experimenting I tried two other things that did not give any measurable improvements:
unicode_util:gc and dc are used by string functions even if the string does not contains any unicode characters, so I tried inlining those functions into the string module to make sure that the huge unicode_util modules is not loaded when not needed. Turns out that is takes very little time to load a single module and that there was no measurable gain.
The PR also includes two smaller drive-by fixes.