Skip to content

Start-time optimizations#11326

Open
garazdawi wants to merge 6 commits into
erlang:masterfrom
garazdawi:lukas/kernel/startup-optimizations
Open

Start-time optimizations#11326
garazdawi wants to merge 6 commits into
erlang:masterfrom
garazdawi:lukas/kernel/startup-optimizations

Conversation

@garazdawi

Copy link
Copy Markdown
Member

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.

Probe Master (ms) Tip (ms) Faster
erl -noshell -eval 'erlang:halt().' 72.5 66.9 −7.8%
escript (source/compile) 119.2 89.5 −24.9%
escript (interpret) 90.8 74.2 −18.2%
escript (precompiled) 72.3 65.0 −10.2%

The escripts just call erlang:halt/0 directly in main/1.

Measured on my M5 Mac.

While experimenting I tried two other things that did not give any measurable improvements:

  1. Don't load unicode_util when using latin-1 string functions.
    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.
  2. Async loading of inet_db. When starting inet_db it reads quite a few files and takes a few ms to do, but doing that start async turned out to be quite hard and error prone and in the end it did not save all that much anyway.

The PR also includes two smaller drive-by fixes.

garazdawi added 6 commits July 2, 2026 13:56
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.
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

CT Test Results

     7 files     615 suites   3h 22m 21s ⏱️
 6 283 tests  5 765 ✅ 516 💤 2 ❌
12 512 runs  11 908 ✅ 602 💤 2 ❌

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

@bjorng

bjorng commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Each start script has a list of modules that will be loaded in parallel by init (the first primLoad tuple in the start script). The list of those modules are found here:

mandatory_modules() ->
[error_handler, %Truly mandatory.
%% Modules that are almost always needed. Listing them here
%% helps the init module to load them faster. Modules not
%% listed here will be loaded by the error_handler module.
%%
%% Keep this list sorted.
application,
application_controller,
application_master,
code,
code_server,
erl_eval,
erl_lint,
erl_parse,
error_logger,
ets,
file,
filename,
file_server,
file_io_server,
gen,
gen_event,
gen_server,
heart,
kernel,
logger,
logger_filters,
logger_server,
logger_backend,
logger_config,
logger_simple_h,
lists,
proc_lib,
supervisor
].

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.

@garazdawi

Copy link
Copy Markdown
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants