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

Excessive inference time for functions with many kwargs #44322

Closed
Keno opened this issue Feb 24, 2022 · 2 comments
Closed

Excessive inference time for functions with many kwargs #44322

Keno opened this issue Feb 24, 2022 · 2 comments
Assignees

Comments

@Keno
Copy link
Member

Keno commented Feb 24, 2022

I have a function with thousands of keyword arguments of which a few hundred are used at any given call site. Inference really doesn't like this and takes several minutes to infer the call. Cursory debugging shows most of the time being spent in haskey(::NamedTuple{<lots of fields here>}). Here is a very minimal reduced example that already shows several second compile times while being trivial (my actual code has non-trivial defaults, etc, which I think makes up the difference):

julia> params = [Expr(:kw, Symbol("k$i"), i) for i = 1:3000]
julia> params2 = reverse([Expr(:kw, Symbol("k$i"), i) for i = 1:600])
julia> @eval function f($(Expr(:parameters, params...)))
       nothing
       end
f (generic function with 1 method)

julia> @eval g() = f($(params2...))
g (generic function with 1 method)

julia> @time @code_typed g()
  7.163038 seconds (7.44 M allocations: 1.996 GiB, 14.41% gc time, 100.00% compilation time)
CodeInfo(
1 ─     return nothing
) => Nothing
@Keno
Copy link
Member Author

Keno commented Feb 24, 2022

Profiling suggests this is another instance of #43999

@JeffBezanson JeffBezanson self-assigned this Feb 24, 2022
JeffBezanson added a commit that referenced this issue Mar 2, 2022
Also use builtins to cut some time inferring into methods.

helps #44322
Keno pushed a commit that referenced this issue Mar 3, 2022
Also use builtins to cut some time inferring into methods.

helps #44322
Keno pushed a commit that referenced this issue Mar 3, 2022
Also use builtins to cut some time inferring into methods.

helps #44322
@Keno
Copy link
Member Author

Keno commented Sep 11, 2022

This is significantly faster on master.

@Keno Keno closed this as completed Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants