-
-
Notifications
You must be signed in to change notification settings - Fork 269
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 invalidations related to * string concat #2325
Conversation
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.
LGTM. I don't know the Pkg internals super-well, so take that FWIW, but overall this looks like a nice enhacement.
@@ -509,7 +509,7 @@ function promptf() | |||
prefix = "" | |||
if project_file !== nothing | |||
if prev_project_file == project_file && prev_project_timestamp == mtime(project_file) | |||
prefix = prev_prefix | |||
prefix = prev_prefix::String | |||
else | |||
project_name = projname(project_file) | |||
if project_name !== nothing |
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.
Is project_name
guaranteed to be a String
when it's not nothing
? Just wondering about the safety of the typeassert (presumably, you're fine).
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.
From what I can tell it should be.. either way, wrt. what gets applied to prev_prefix
the product of string()
is always String
, I believe??
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.
To play it safe I've reverted the type assert
src/API.jl
Outdated
@@ -1008,7 +1009,7 @@ function precompile(ctx::Context; internal_call::Bool=false, kwargs...) | |||
end | |||
depsmap = Dict{Base.PkgId, Vector{Base.PkgId}}(Iterators.filter(!isnothing, deps_pair_or_nothing)) #flat map of each dep and its deps | |||
|
|||
if ctx.env.pkg !== nothing && isfile( joinpath( dirname(ctx.env.project_file), "src", ctx.env.pkg.name * ".jl") ) | |||
if ctx.env.pkg !== nothing && isfile( joinpath( dirname(ctx.env.project_file), "src", string(ctx.env.pkg.name, ".jl")) ) |
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.
I think the standard way of doing this is:
ctx_env_pkg = ctx.env.pkg
if ctx_env_pkg !== nothing && isfile( joinpath( dirname(ctx.env.project_file), "src", ctx_env_pkg.name * ".jl") )
Basically, hoist the load of the thing we check for nothing
so that Julia realizes it cannot have changed the next time we use it. Changing *
to string
is mostly a bandaid.
If things are well inferred it shouldn't matter if you use |
Agreed. I couldn't figure out where the inference issues where, but your pointers help. I'll take a stab at fixing them. Thanks But I think I'll leave the |
👍 |
Validated to still eliminate
|
If you provide your versions of Julia & ChainRulesCore I can take a peek. On 1.6 and ChainRulesCore v0.9.25, I'm seeing invalidation of the bodyfunction for |
@timholy Sorry, I meant that this PR still fixes (removes) the invalidations I listed, after the review edit commit. Bad choice of wording |
src/API.jl
Outdated
@@ -114,13 +114,15 @@ end | |||
|
|||
function check_package_name(x::AbstractString, mode=nothing) |
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.
I'm still a bit confused about whether this PR does everything you want it to. If not, one "cheap" way to get better inference is to make the signature check_package_name(x::String, mode::Union{Nothing,SomeType}=nothing)
and then also provide an argument-standardizing method
check_package_name(x::AbstractString, mode=nothing) = check_package_name(String(x)::String, convert(Union{Nothing,SomeType}, mode)::Union{Nothing,SomeType})
The typeasserts guarantee you'll never get a StackOverflowError.
Ah, sorry, I just saw this. This seems to fix the same invalidations as #2376. While that one is more minimal, we might still want to go with this one instead because of the style and performance improvements. |
If @IanButterworth thinks this is good to go, I'm fine with it. I was just confused about what state this was in. From #2376 it looks like there may be |
5d4da26
to
b6e5690
Compare
Sorry @timholy, my understanding of this was a bit fragile and only got back around to it now. I've narrowed the def of
I'll merge once tests pass |
…try is functional
* Avoid invalidations related to * string concat * use same JULIA_PKG_SERVER setting for processcoverage to ensure registry is functional (cherry picked from commit 42fc1bf)
I noticed that loading Flux was causing Pkg latency, which on investigation seems to be due to
ChainRulesCore
's necessarily broad*
methods (JuliaDiff/ChainRulesCore.jl#273) and the use of*
for string concat in PkgBefore:
The
Pkg.API.var"#precompile#195"
invalidation seems most substantialThis PR eliminates the
Pkg.REPLMode.promptf()
andPkg.API.var"#precompile#195"
invalidations