-
Notifications
You must be signed in to change notification settings - Fork 4
Description
I've experienced quite extreme compile times for some functions, here's an example
julia> using DescriptorSystems
julia> G = rss(2,2,4);
julia> @time gnugap(G, G)
59.315304 seconds (185.38 M allocations: 10.129 GiB, 6.14% gc time, 99.97% compilation time)
(6.598356591423948e-16, 2.55648096966907)This problem is likely to be related to #8, since type piracy is likely to lead to method invalidations and inference problems that in turn cause recompilation of a lot of base methods. To investigate this hypothesis, we can make use of SnoopCompile.jl
using Revise
using SnoopCompileCore
using DescriptorSystems;
G = rss(2,2,4);
tinf = @snoopi_deep gnugap(G, G)
using ProfileView, SnoopCompile
ProfileView.view(flamegraph(tinf))This displays the following graph

The colored flames indicates stacks, and their extent in the horizontal direction indicate their run time. Notice how there is a large horizontal gap in the flame graph, followed immediately by the stack for Base.typed_hvcat (where I've held the mouse to display the method name in the screenshot. This is a clear indication that the type piracy of #8 causes huge compile times, likely due to type inference problems.
Running
@code_warntype [G G]indicates that there are type inference problems present when concatenating systems:
julia> @code_warntype [G G]
MethodInstance for hcat(::DescriptorStateSpace{Float64}, ::DescriptorStateSpace{Float64})
from hcat(SYS1::DescriptorStateSpace, SYS2::DescriptorStateSpace) in DescriptorSystems at /home/fredrikb/.julia/packages/DescriptorSystems/20HLg/src/connections.jl:71
Arguments
#self#::Core.Const(hcat)
SYS1::DescriptorStateSpace{Float64}
SYS2::DescriptorStateSpace{Float64}
Locals
D::Matrix{Float64}
C::Matrix{Float64}
B::Matrix{Float64}
blockdims::Vector{Int64}
E::Any
A::Matrix{Float64}
Ts::Float64
T::Type{Float64}
ny::Any
@_13::Union{UniformScaling, Matrix{Float64}}
@_14::Union{UniformScaling, Matrix{Float64}}
notice variables E::Any and @_13::Union{UniformScaling, Matrix{Float64}}.
The other gaps in the flame graph points to the folowing methods
function Base.hvcat(rows::Tuple{Vararg{Int}}, A::Union{DescriptorStateSpace, AbstractVecOrMat{<:Number}, Number, UniformScaling}...)
as well as https://github.com/andreasvarga/DescriptorSystems.jl/blob/main/src/dss.jl#L52