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

define method Base.convert(::Type{Nothing}, ::MyType) causes latency/recompilation when using in second time #51389

Closed
songjhaha opened this issue Sep 19, 2023 · 2 comments
Labels
compiler:latency Compiler latency

Comments

@songjhaha
Copy link

Here is a small example to reproudce this problem:

  1. create a package and define a new Type;
  2. define convert method for convert this new Type to Type Nothing;
  3. estimate loading time with using MyPkg twice, the second time using is very very slow and looks like doing recompilation;

Julia Version: 1.9.3
OS: I reproduce this problem in both Win10 && Unbuntu

module MyPkg

struct MyCls end

Base.convert(::Type{Nothing}, x::MyCls) = 1

end # module MyPkg
julia> @time using MyPkg
  0.015626 seconds (8.70 k allocations: 582.849 KiB)

julia> @time using MyPkg
  2.311770 seconds (1.30 M allocations: 91.081 MiB, 3.68% gc time, 99.92% compilation time: 100% of which was recompilation)
@johnnychen94
Copy link
Sponsor Member

johnnychen94 commented Sep 19, 2023

This doesn't occur at Julia 1.10.0-beta2. Possibly already fixed by #49349

using SnoopCompileCore
invalidations = @snoor using myy

using SnoopCompile
length(uinvalidated(invalidations)) 

There were 2659 invalidations in Julia 1.9.3, and only 3 invalidations in Julia 1.10.0-beta2.
I believe the latency for the second loading is due to these invalidations.

See also some pre-1.9 PRs:

@KristofferC
Copy link
Sponsor Member

You also wouldn't notice this in 1.10 due to #49525

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

No branches or pull requests

3 participants