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

Avoid duplicate stat calls during startup/loading #55331

Merged
merged 8 commits into from
Aug 2, 2024

Conversation

IanButterworth
Copy link
Sponsor Member

Avoids immediately successive stat calls for the same path during startup & loading.

According to MacOS Instruments this reduces stat64 calls during --start=no -e "using Pkg" from 844 to 672.

On MacOS I don't see a speed improvement, but on WSL2 @timholy reported the test from #55171 sees a modest improvement.

This PR (10 iterations)

tim@diva:~/.julia/bin$ time for i in {1..10}; do ./cli --help &> /dev/null; done

real    0m2.999s
user    0m3.547s
sys     0m6.552s

master

real    0m3.217s
user    0m3.794s
sys     0m6.700s

1.11-rc2:

real    0m3.746s
user    0m4.169s
sys     0m6.755s

I left the @debugs in as they might be useful for similar investigations.

@IanButterworth IanButterworth added the packages Package management and loading label Aug 1, 2024
Comment on lines 824 to 835
function entry_point_and_project_file(dir::String, name::String)::Union{Tuple{Nothing,Nothing},Tuple{String,Nothing},Tuple{String,String}}
path = normpath(joinpath(dir, "$name.jl"))
isfile_casesensitive(path) && return path, nothing
dir_name = joinpath(dir, name)
path, project_file = entry_point_and_project_file_inside(dir_name, name)
path === nothing || return path, project_file
dir_jl = dir_name * ".jl"
path, project_file = entry_point_and_project_file_inside(dir_jl, name)
path === nothing || return path, project_file
# check for less likely case with a bare file and no src directory last to minimize stat calls
path = normpath(joinpath(dir, "$name.jl"))
isfile_casesensitive(path) && return path, nothing
return nothing, nothing
end
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is a breaking change in precedence between a bare Foo.jl and Foo.jl/src/Foo.jl because both couldn't coexist?

base/stat.jl Outdated
stat(path::AbstractString) = @stat_call jl_stat Cstring path
lstat(path::AbstractString) = @stat_call jl_lstat Cstring path
function stat(path::AbstractString)
@debug "stat($(repr(path)))" exception=(ErrorException("Fake error for backtrace printing"),stacktrace())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to stay in?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OP says

I left the @debugs in as they might be useful for similar investigations.

@KristofferC
Copy link
Sponsor Member

I personally don't really like leaving these @debugs in. They feel a bit too noisy and bespoke for this specific use case.

@topolarity
Copy link
Member

Agreed - they also add an inference burden, can inhibit inlining, and even introduce spurious allocations.

base/stat.jl Outdated Show resolved Hide resolved
base/stat.jl Outdated Show resolved Hide resolved
@IanButterworth
Copy link
Sponsor Member Author

@KristofferC any idea why I had to revert eea60dd (#55331) to make tests pass?

Prior to that I was getting lots of

�_bk;t=1722485957688��[91m�[1mTest Failed�[22m�[39m at �[39m�[1m/cache/build/tester-amdci4-12/julialang/julia-master/julia-5934304079/share/julia/test/loading.jl:614�[22m

�_bk;t=1722485957688�  Expression: path == get(paths, id, nothing)

�_bk;t=1722485957688�   Evaluated: "/cache/build/tester-amdci4-12/julialang/julia-master/tmp/jl_DfNP3O/src/A.jl" == nothing

@KristofferC
Copy link
Sponsor Member

Not sure from just looking at the code.

@KristofferC KristofferC merged commit c6732a7 into JuliaLang:master Aug 2, 2024
7 checks passed
lazarusA pushed a commit to lazarusA/julia that referenced this pull request Aug 17, 2024
Avoids immediately successive stat calls for the same path during
startup & loading.

According to MacOS Instruments this reduces `stat64` calls during
`--start=no -e "using Pkg"` from 844 to 672.

On MacOS I don't see a speed improvement, but on WSL2 @timholy reported
the test from JuliaLang#55171 sees a
modest improvement.

This PR (10 iterations)
```
tim@diva:~/.julia/bin$ time for i in {1..10}; do ./cli --help &> /dev/null; done

real    0m2.999s
user    0m3.547s
sys     0m6.552s
```

master
```
real    0m3.217s
user    0m3.794s
sys     0m6.700s
```
1.11-rc2:
```
real    0m3.746s
user    0m4.169s
sys     0m6.755s
```

I left the `@debug`s in as they might be useful for similar
investigations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages Package management and loading
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants