Skip to content

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

Closed
@songjhaha

Description

@songjhaha

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions