prevent doing excessive file system checks in require calls #40890
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.
Ref #40570
Some background on the code loading code:
The parsing of TOML files used to be implemented completely stateless. When asking for example what UUID a package the TOML parsing system would look through the TOML files line by line until it found it. Asking for another package, it would start from scratch again. This caused these files to have to be opened and closed a large number of times #27414 (comment).
In #36018 code loading was made to use a real TOML parser and in #37906 a cache was introduced to avoid having to reparse the same TOML file over and over.
However, a lot of the "statelessness" from the old code loading still exists. For example, every time
load_path
is called, Julia goes through the file system and looks around for project files. This is called many many times for a singleusing
call. One way to measure how much julia hits the file system is by running withstrace
and looking for differentstat
calls:Looking in the file we can for example see
being called over and over (corresponding to
julia/base/loading.jl
Line 133 in 27066a7
This PR assumes that within a single
require
calls, things like the load path, the content of Project files, etc will not change. This is a bit similar to the restriction we have on "world age".With this PR we get:
which is a quite significant reduction.
I admit that the implementation here is ugly but I consider this just as an ephemeral state of things for 1.7. For 1.8 I want to do a proper update of the code loading and do something similar that was started in #37632 to propagate path info to precompile workers so that only the main worker has to do any package location lookups.
@mkitti perhaps you could do some measurements on Windows and see if this improves #40570?