Skip to content

methods seems to get 100x slower than in v1.5 #38059

@aviatesk

Description

@aviatesk

MRE:

[email protected]

julia> methods(show);

julia> length(methods(show))
304

julia> @time methods(show);
  0.000278 seconds (966 allocations: 46.531 KiB)

julia@master

julia> methods(show);

julia> length(methods(show))
314

julia> @time methods(show);
  0.022454 seconds (14.80 k allocations: 812.578 KiB)

The profiling shows most of the time is spent in _methods_by_ftype, and I guess #35983 might be the source of this.


Well, I'm not sure the performance for methods is critical; I found this problem just because Juno's completions are much slower than before when using Julia built from master, and profiling shows that this line calling methods is the source of the performance regression:
https://github.com/JunoLab/Atom.jl/blob/c751731bd488db815110ed7771b7f313d8b92116/src/utils.jl#L268

ismacro(f::Function) = startswith(string(methods(f).mt.name), "@")

Now I found changing this line into

function ismacro(@nospecialize(f::FT)) where {FT<:Function}
  isdefined(FT, :name) || return false
  tn = FT.name::Core.TypeName
  return occursin('@', string(tn.name))
end

gets rid of the performance regression anyway, so I'm okay with it if the slowness of methods can't be helped in order to circumvent the latency issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions