Use code_server path cache in code:where_is_file/1 #8078
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.
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
.