Skip to content

Commit 13fc4c3

Browse files
authored
some latency hacks (#30566)
These changes cut some method dependency edges that tend to lead to invalidations when loading packages.
1 parent 1da48c2 commit 13fc4c3

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

base/array.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ offset `do`. Return `dest`.
268268
"""
269269
function copyto!(dest::Array{T}, doffs::Integer, src::Array{T}, soffs::Integer, n::Integer) where T
270270
n == 0 && return dest
271-
n > 0 || _throw_argerror(n)
271+
n > 0 || _throw_argerror()
272272
if soffs < 1 || doffs < 1 || soffs+n-1 > length(src) || doffs+n-1 > length(dest)
273273
throw(BoundsError())
274274
end
@@ -277,10 +277,11 @@ function copyto!(dest::Array{T}, doffs::Integer, src::Array{T}, soffs::Integer,
277277
end
278278

279279
# Outlining this because otherwise a catastrophic inference slowdown
280-
# occurs, see discussion in #27874
281-
function _throw_argerror(n)
280+
# occurs, see discussion in #27874.
281+
# It is also mitigated by using a constant string.
282+
function _throw_argerror()
282283
@_noinline_meta
283-
throw(ArgumentError(string("tried to copy n=", n, " elements, but n should be nonnegative")))
284+
throw(ArgumentError("Number of elements to copy must be nonnegative."))
284285
end
285286

286287
copyto!(dest::Array{T}, src::Array{T}) where {T} = copyto!(dest, 1, src, 1, length(src))

base/checked.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function checked_neg(x::T) where T<:Integer
8787
checked_sub(T(0), x)
8888
end
8989
throw_overflowerr_negation(x) = (@_noinline_meta;
90-
throw(OverflowError("checked arithmetic: cannot compute -x for x = $x::$(typeof(x))")))
90+
throw(OverflowError(Base.invokelatest(string, "checked arithmetic: cannot compute -x for x = ", x, "::", typeof(x)))))
9191
if BrokenSignedInt != Union{}
9292
function checked_neg(x::BrokenSignedInt)
9393
r = -x
@@ -151,7 +151,7 @@ end
151151

152152

153153
throw_overflowerr_binaryop(op, x, y) = (@_noinline_meta;
154-
throw(OverflowError("$x $op $y overflowed for type $(typeof(x))")))
154+
throw(OverflowError(Base.invokelatest(string, x, " ", op, "y", " overflowed for type ", typeof(x)))))
155155

156156
"""
157157
Base.checked_add(x, y)

base/show.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,14 @@ function show_type_name(io::IO, tn::Core.TypeName)
455455
globname = isdefined(tn, :mt) ? tn.mt.name : nothing
456456
globfunc = false
457457
if globname !== nothing
458-
globname_str = string(globname)
458+
globname_str = string(globname::Symbol)
459459
if ('#' globname_str && '@' globname_str && isdefined(tn, :module) &&
460460
isbindingresolved(tn.module, globname) && isdefined(tn.module, globname) &&
461461
isconcretetype(tn.wrapper) && isa(getfield(tn.module, globname), tn.wrapper))
462462
globfunc = true
463463
end
464464
end
465-
sym = globfunc ? globname : tn.name
465+
sym = (globfunc ? globname : tn.name)::Symbol
466466
if get(io, :compact, false)
467467
if globfunc
468468
return print(io, "typeof(", sym, ")")

base/strings/io.jl

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ end
105105

106106
tostr_sizehint(x) = 8
107107
tostr_sizehint(x::AbstractString) = lastindex(x)
108+
tostr_sizehint(x::Union{String,SubString{String}}) = sizeof(x)
108109
tostr_sizehint(x::Float64) = 20
109110
tostr_sizehint(x::Float32) = 12
110111

stdlib/Distributed/src/managers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ manage
373373
struct DefaultClusterManager <: ClusterManager
374374
end
375375

376-
const tunnel_hosts_map = Dict{AbstractString, Semaphore}()
376+
const tunnel_hosts_map = Dict{String, Semaphore}()
377377

378378
"""
379379
connect(manager::ClusterManager, pid::Int, config::WorkerConfig) -> (instrm::IO, outstrm::IO)

0 commit comments

Comments
 (0)