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

fix invalidations when loading ForwardDiff.jl and ChainRulesCore.jl #47091

Merged
merged 1 commit into from
Oct 10, 2022

Conversation

ranocha
Copy link
Member

@ranocha ranocha commented Oct 7, 2022

I improved type stability to fix some invalidations. This is based on the following code (executed with a local build using the backports-release-1.8 branch):

julia> import Pkg; Pkg.activate(temp=true); Pkg.add("ForwardDiff")

julia> using SnoopCompileCore; invalidations = @snoopr(using ForwardDiff); using SnoopCompile

julia> length(uinvalidated(invalidations))
430

julia> trees = invalidation_trees(invalidations)
...
 inserting promote_rule(::Type{R}, ::Type{ForwardDiff.Dual{T, V, N}}) where {R<:Real, T, V, N} in ForwardDiff at ~/.julia/packages/ForwardDiff/pDtsf/src/dual.jl:425 invalidated:
   backedges: 1: superseding promote_rule(::Type, ::Type) in Base at promotion.jl:310 with MethodInstance for promote_rule(::Type{Int64}, ::Type{S} where S<:Real) (1 children)
              2: superseding promote_rule(::Type, ::Type) in Base at promotion.jl:310 with MethodInstance for promote_rule(::Type{Int64}, ::Type) (228 children)
   17 mt_cache
...

With this PR on top of the current backports-release-1.8 branch:

julia> length(uinvalidated(invalidations))
191

Most of the remaining invalidations could be fixed around sort_int_range!. However, this part changed quite a bit on master, so I'm not sure whether it's better to wait until v1.9 is released to revisit this issue.

Edit: It's nice to observe that this fixes JuliaDiff/ChainRulesCore.jl#576:

julia> import Pkg; Pkg.activate(temp=true); Pkg.add("ChainRulesCore")
  Activating new project at `/tmp/jl_8BxH6u`
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `/tmp/jl_8BxH6u/Project.toml`
  [d360d2e6] + ChainRulesCore v1.15.6
    Updating `/tmp/jl_8BxH6u/Manifest.toml`
  [d360d2e6] + ChainRulesCore v1.15.6
  [34da2185] + Compat v4.3.0
  [56f22d72] + Artifacts
  [ade2ca70] + Dates
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [de0858da] + Printf
  [9a3f8284] + Random
  [ea8e919c] + SHA v0.7.0
  [9e88b42a] + Serialization
  [2f01184e] + SparseArrays
  [cf7118a7] + UUIDs
  [4ec0a83e] + Unicode
  [e66e0078] + CompilerSupportLibraries_jll v0.5.2+0
  [4536629a] + OpenBLAS_jll v0.3.21+0
  [8e850b90] + libblastrampoline_jll v5.2.0+0

julia> using SnoopCompileCore; invalidations = @snoopr(using ChainRulesCore); using SnoopCompile
[ Info: Precompiling SnoopCompile [aa65fe97-06da-5843-b5b1-d5d13cad87d2]

julia> length(uinvalidated(invalidations))
0

julia> trees = invalidation_trees(invalidations)
SnoopCompile.MethodInvalidations[]

(with this PR on top of the current backports-release-1.8 branch).

@ranocha ranocha added compiler:latency Compiler latency backport 1.8 Change should be backported to release-1.8 labels Oct 7, 2022
@ranocha ranocha changed the title fix invalidations when loading ForwardDiff.jl fix invalidations when loading ForwardDiff.jl and ChainRulesCore.jl Oct 7, 2022
@KristofferC KristofferC merged commit 0dada17 into JuliaLang:master Oct 10, 2022
@ranocha ranocha deleted the hr/invalidations_ForwardDiff branch October 12, 2022 11:28
KristofferC pushed a commit that referenced this pull request Oct 27, 2022
@KristofferC KristofferC mentioned this pull request Oct 27, 2022
37 tasks
KristofferC pushed a commit that referenced this pull request Oct 28, 2022
@KristofferC KristofferC removed the backport 1.8 Change should be backported to release-1.8 label Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:latency Compiler latency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalidations from ChainRulesCore Tangent overload on Tail
2 participants