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

Vararg constructor is bad news for compiling big types (regression vs 0.5) #22389

Open
SimonDanisch opened this issue Jun 15, 2017 · 1 comment
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@SimonDanisch
Copy link
Contributor

Julia 0.6 rc3:

module VisualizeTypes
abstract type Composable end
(::Type{T}){T <: Composable, N}(c::Vararg{Pair, N}) = T(c) # Remove the varar
type Window{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18} <: Composable
    Area::T1
    Open::T2
    EnteredWindow::T3
    Focused::T4
    MouseInside::T5
    MouseButtons::T6
    MousePosition::T7
    MouseScroll::T8
    MouseDrag::T9
    KeyboardButtons::T10
    KeyboardUnicode::T11
    DroppedFiles::T12
    NativeWindow::T13
    Camera::T14
    Renderlist::T15
    Scene::T16
    Color::T17
    Light::T18
end

end 

This module takes ~40s to compile. Remove the Vararg and change it to anything else will make the compilation time go down to 0.4s.

@JeffBezanson JeffBezanson added the types and dispatch Types, subtyping and method dispatch label Jun 15, 2017
@vtjnash
Copy link
Member

vtjnash commented Mar 29, 2022

Reducible to:

julia> @time typeintersect(Tuple{Vararg{Pair}}, Tuple{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18} where {T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18})
  4.325776 seconds (7.08 M allocations: 2.250 GiB, 1.44% gc time)
Tuple{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18} where {T1<:Pair, T2<:Pair, T3<:Pair, T4<:Pair, T5<:Pair, T6<:Pair, T7<:Pair, T8<:Pair, T9<:Pair, T10<:Pair, T11<:Pair, T12<:Pair, T13<:Pair, T14<:Pair, T15<:Pair, T16<:Pair, T17<:Pair, T18<:Pair}

Would be interesting to know if there is a simple fix here, but not sure it would be a general performance improvement. Just avoid adding constraints to your function parameters and life will quite often be good or at least better.

This was referenced Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

3 participants