Skip to content

Commit

Permalink
Narrow convert methods to reduce invalidations
Browse files Browse the repository at this point in the history
This package caused >1000 invalidations for DifferentialEquations.
The main problem is a pair of `convert` methods: one is redundant with
a method in Base (and needlessly invalidates some code),
and another intersected with signatures like
`convert(Base.SHA1, ::Any)` and other crazy types.
The reason is because the `T` in `APL{T}` is completely unconstrained,
and consequently it's possible in principle for it to be a
`REPLTerminal` or a `Module` or whatever. It didn't seem as if that were
the real intent of the convert method.
  • Loading branch information
timholy committed Aug 13, 2021
1 parent 49eb7da commit 040b236
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ function Base.convert(::Type{T}, p::AbstractPolynomial) where T <: AbstractTermL
end

MA.scaling(p::AbstractPolynomialLike{T}) where {T} = convert(T, p)
Base.convert(::Type{Any}, p::APL) = p
# Conversion polynomial -> scalar
function Base.convert(S::Type{<:Union{Number, T}}, p::APL{T}) where T
function Base.convert(S::Type{<:Union{Number, T}}, p::APL{T}) where T<:Number
s = zero(S)
for t in terms(p)
if !isconstant(t)
Expand Down

0 comments on commit 040b236

Please sign in to comment.