Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

the-mikedavis
Copy link
Contributor

@the-mikedavis the-mikedavis commented Jan 31, 2024

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 since #6729 / #8049. Re-using and updating that cache when searching for '.app' files in application:load/1 can improve its runtime, especially when loading multiple applications.

Internally to make this possible I've added a code_server:where_is_file/1 function that the application_controller uses instead of code: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 the code: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 of rabbitmqctl --help (30% of the total run time). It also improves boot time for the broker since application:load/1 is used by application:start/2.

Copy link
Contributor

github-actions bot commented Jan 31, 2024

CT Test Results

    2 files     67 suites   1h 1m 48s ⏱️
1 526 tests 1 272 ✅ 254 💤 0 ❌
1 727 runs  1 424 ✅ 303 💤 0 ❌

Results for commit 63eb86a.

♻️ 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

@jhogberg jhogberg added the team:VM Assigned to OTP team VM label Feb 5, 2024
@josevalim
Copy link
Contributor

@the-mikedavis perhaps it would make sense to change code:where_is_file/1 itself to go through the code server and use the cache? This would optimize both which and where_is_file as well.

`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`.
@the-mikedavis the-mikedavis changed the title Use code_server path cache for finding .app files Use code_server path cache in code:where_is_file/1 Feb 13, 2024
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.

None yet

4 participants