Skip to content

Commit

Permalink
Reduce invalidations when loading JuliaData packages (#47889)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Dec 15, 2022
1 parent 7b10d5f commit e84634e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ include("idset.jl")
include("iterators.jl")
using .Iterators: zip, enumerate, only
using .Iterators: Flatten, Filter, product # for generators
using .Iterators: Stateful # compat (was formerly used in reinterpretarray.jl)

include("namedtuple.jl")

Expand Down
7 changes: 4 additions & 3 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2730,7 +2730,8 @@ keepat!(a::Vector, m::AbstractVector{Bool}) = _keepat!(a, m)
# set-like operators for vectors
# These are moderately efficient, preserve order, and remove dupes.

_unique_filter!(pred, update!, state) = function (x)
_unique_filter!(pred::P, update!::U, state) where {P,U} = function (x)
# P, U force specialization
if pred(x, state)
update!(state, x)
true
Expand All @@ -2756,7 +2757,7 @@ union!(v::AbstractVector{T}, itrs...) where {T} =
symdiff!(v::AbstractVector{T}, itrs...) where {T} =
_grow!(_shrink_filter!(symdiff!(Set{T}(), v, itrs...)), v, itrs)

function _shrink!(shrinker!, v::AbstractVector, itrs)
function _shrink!(shrinker!::F, v::AbstractVector, itrs) where F
seen = Set{eltype(v)}()
filter!(_grow_filter!(seen), v)
shrinker!(seen, itrs...)
Expand All @@ -2768,7 +2769,7 @@ setdiff!( v::AbstractVector, itrs...) = _shrink!(setdiff!, v, itrs)

vectorfilter(T::Type, f, v) = T[x for x in v if f(x)]

function _shrink(shrinker!, itr, itrs)
function _shrink(shrinker!::F, itr, itrs) where F
T = promote_eltype(itr, itrs...)
keep = shrinker!(Set{T}(itr), itrs...)
vectorfilter(T, _shrink_filter!(keep), itr)
Expand Down
3 changes: 2 additions & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,8 @@ function explicit_manifest_uuid_path(project_file::String, pkg::PkgId)::Union{No
end
end
# Extensions
for (name, entries::Vector{Any}) in d
for (name, entries) in d
entries = entries::Vector{Any}
for entry in entries
uuid = get(entry, "uuid", nothing)::Union{Nothing, String}
extensions = get(entry, "extensions", nothing)::Union{Nothing, Dict{String, Any}}
Expand Down
4 changes: 2 additions & 2 deletions base/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ function logmsg_code(_module, file, line, level, message, exs...)
id = $(log_data._id)
# Second chance at an early bail-out (before computing the message),
# based on arbitrary logger-specific logic.
if _invoked_shouldlog(logger, level, _module, group, id)
if invokelatest(shouldlog, logger, level, _module, group, id)
file = $(log_data._file)
if file isa String
file = Base.fixup_stdlib_path(file)
end
line = $(log_data._line)
local msg, kwargs
$(logrecord) && handle_message(
$(logrecord) && invokelatest(handle_message,
logger, level, msg, _module, group, id, file, line;
kwargs...)
end
Expand Down
16 changes: 7 additions & 9 deletions base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -722,25 +722,23 @@ function CyclePadding(T::DataType)
CyclePadding(pad, as)
end

using .Iterators: Stateful
@assume_effects :total function array_subpadding(S, T)
checked_size = 0
lcm_size = lcm(sizeof(S), sizeof(T))
s, t = Stateful{<:Any, Any}(CyclePadding(S)),
Stateful{<:Any, Any}(CyclePadding(T))
s, t = CyclePadding(S), CyclePadding(T)
isempty(t) && return true
isempty(s) && return false
checked_size = 0
ps, sstate = iterate(s) # use of Stateful harms inference and makes this vulnerable to invalidation
pad, tstate = iterate(t)
while checked_size < lcm_size
# Take padding in T
pad = popfirst!(t)
# See if there's corresponding padding in S
while true
ps = peek(s)
# See if there's corresponding padding in S
ps.offset > pad.offset && return false
intersect(ps, pad) == pad && break
popfirst!(s)
ps, sstate = iterate(s, sstate)
end
checked_size = pad.offset + pad.size
pad, tstate = iterate(t, tstate)
end
return true
end
Expand Down
13 changes: 9 additions & 4 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1881,8 +1881,12 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
# .
print(io, '.')
# item
parens = !(field isa Symbol) || (field::Symbol in quoted_syms)
quoted = parens || isoperator(field)
if isa(field, Symbol)
parens = field in quoted_syms
quoted = parens || isoperator(field)
else
parens = quoted = true
end
quoted && print(io, ':')
parens && print(io, '(')
show_unquoted(io, field, indent, 0, quote_level)
Expand Down Expand Up @@ -2006,10 +2010,11 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In

# binary operator (i.e. "x + y")
elseif func_prec > 0 # is a binary operator
func = func::Symbol # operator_precedence returns func_prec == 0 for non-Symbol
na = length(func_args)
if (na == 2 || (na > 2 && isa(func, Symbol) && func in (:+, :++, :*)) || (na == 3 && func === :(:))) &&
if (na == 2 || (na > 2 && func in (:+, :++, :*)) || (na == 3 && func === :(:))) &&
all(a -> !isa(a, Expr) || a.head !== :..., func_args)
sep = func === :(:) ? "$func" : " " * convert(String, string(func))::String * " " # if func::Any, avoid string interpolation (invalidation)
sep = func === :(:) ? "$func" : " $func "

if func_prec <= prec
show_enclosed_list(io, '(', func_args, sep, ')', indent, func_prec, quote_level, true)
Expand Down
2 changes: 1 addition & 1 deletion base/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ julia> hex2bytes(a)
"""
function hex2bytes end

hex2bytes(s) = hex2bytes!(Vector{UInt8}(undef, length(s) >> 1), s)
hex2bytes(s) = hex2bytes!(Vector{UInt8}(undef, length(s)::Int >> 1), s)

# special case - valid bytes are checked in the generic implementation
function hex2bytes!(dest::AbstractArray{UInt8}, s::String)
Expand Down

2 comments on commit e84634e

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.