-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use code_server path cache in code:where_is_file/1 #8078
Use code_server path cache in code:where_is_file/1 #8078
Conversation
CT Test Results 2 files 70 suites 1h 2m 59s ⏱️ For more details on these failures, see this check. Results for commit c8687e3. ♻️ 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 |
596f3d0
to
47d5985
Compare
@the-mikedavis perhaps it would make sense to change |
47d5985
to
63eb86a
Compare
Does it make sense if which(Module) when is_atom(Module) ->
case is_loaded(Module) of
false ->
which(Module, get_path());
{file, File} ->
File
end. Gets updated to: which(Module) when is_atom(Module) ->
case is_loaded(Module) of
false ->
File = atom_to_list(Module) ++ objfile_extension(),
where_is_file(File);
{file, File} ->
File
end. The |
@kikofernandez I agree it makes sense. Perhaps we should get rid of |
I initially thought so, but I do not fully understand the "why" certain things are as they are. It could be that we simply move the implementation of %% Note that we don't want to go via which/1, since it doesn't look at the
%% disk contents at all if the module is already loaded.
module_status(Module, PathFiles) ->
case is_loaded(Module) of
false -> not_loaded;
{file, preloaded} -> loaded;
{file, cover_compiled} ->
%% Cover compilation loads directly to memory and does not
%% create a beam file, so report 'modified' if a file exists.
case which(Module, PathFiles) of
non_existing -> removed;
_File -> modified
end; |
63eb86a
to
4a32d63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Unless someone objects, I will merge in a few days.
Thanks!
`application:load/1` slows down as the number of directories in the code path increases because the call to `code:where_is_file/1` for the '.app' file must scan each directory for the app. The code_server maintains a cache of the contents of directories in the path depending on their `code:cache()` setting. Re-using and updating that cache when searching for '.app' files in `application:load/1` can improve its runtime, especially when loading multiple applications. For a reasonably large project (RabbitMQ) with a high number of code path dirs (111 at time of writing), loading an application might take upwards of 20ms. With the code_server's cache, loading each application takes at most around half of a millisecond instead. `application:load/1` is used for loading plugins in Rabbit's CLI for example, and this change can save as much as 750ms for a run of `rabbitmqctl --help` (30% of the total run time). It also improves the boot time for the broker since `application:load/1` is used by `application:start/2`.
Co-authored-by: Kiko Fernandez-Reyes <[email protected]>
4a32d63
to
c8687e3
Compare
application:load/1
slows down as the number of directories in the code path increases because the call tocode:where_is_file/1
for the '.app' file must scan each directory for the app. The code_server maintains a cache of the contents of directories in the path depending on theircode:cache()
setting since #6729 / #8049. Re-using and updating that cache when searching for '.app' files inapplication:load/1
can improve its runtime, especially when loading multiple applications.Internally to make this possible I've added acode_server:where_is_file/1
function that the application_controller uses instead ofcode:where_is_file/1
. This re-uses the code_server's existing cache helper functions to find the file and update the caches along the way, respecting thecode:cache()
option for each dir.For a reasonably large project (RabbitMQ) with a high number of code path dirs (111 at time of writing), loading an application might take upwards of 20ms. With the code_server's cache, loading each application takes at most around half of a millisecond instead.
application:load/1
is used for loading plugins in Rabbit's CLI for example, and this change can save as much as 750ms for a run ofrabbitmqctl --help
(30% of the total run time). It also improves boot time for the broker sinceapplication:load/1
is used byapplication:start/2
.