bsc-quantic / Tenet.jl

Composable Tensor Network library in Julia
https://bsc-quantic.github.io/Tenet.jl/
Apache License 2.0
18 stars 1 forks source link

Reduce package load time by lazily loading Makie #2

Closed mofeing closed 1 year ago

mofeing commented 1 year ago

Currently, Tenet takes about 11s to load in my laptop (Apple M1 Pro). Julia 1.9 should provide some improvements on native code caching. Meanwhile, we could lazily load packages to avoid unnecessary load overhead.

An analysis on the package load time using InteractiveUtils.@time_imports (see below) shows that the Makie package (used for visualization of tensor networks) takes around half of the time.

Since visualization is not critical and Makie is a popular package that people will most probably load in their sessions, we could use Requires.jl for lazily loading Makie-dependent code. Furthermore, Package Extensions should land on Julia 1.9 so Requires would be a dependency just for Julia 1.8.

julia> using InteractiveUtils
julia> @time_imports using Tenet
     16.4 ms  MacroTools
      1.2 ms  SimpleTraits
      2.0 ms  StaticArraysCore
    396.0 ms  StaticArrays
      3.1 ms  ArnoldiMethod
      0.5 ms  Compat
      0.4 ms  Inflate
     56.2 ms  DataStructures
     31.4 ms  Graphs
      1.2 ms  Contour
      0.6 ms  LaTeXStrings
     13.1 ms  AbstractTrees
     35.0 ms  SIMD
      0.7 ms  ScanByte
      1.3 ms  TranscodingStreams
      4.3 ms  Automa
     19.5 ms  Preferences
      0.3 ms  JLLWrappers
    158.5 ms  Bzip2_jll 99.58% compilation time (100% recompilation)
      0.8 ms  Zlib_jll
      0.5 ms  FreeType2_jll
      2.9 ms  CEnum
      3.9 ms  FreeType
     60.6 ms  FixedPointNumbers
      0.1 ms  Reexport
     55.6 ms  ColorTypes 6.46% compilation time
    220.6 ms  Colors
      4.0 ms  IrrationalConstants
     75.4 ms  ChainRulesCore
      2.4 ms  DocStringExtensions 54.33% compilation time
      9.9 ms  ChangesOfVariables
      1.2 ms  InverseFunctions
      0.5 ms  LogExpFunctions
      0.8 ms  OpenLibm_jll
      6.3 ms  CompilerSupportLibraries_jll
      0.5 ms  OpenSpecFun_jll
     12.1 ms  SpecialFunctions
      0.2 ms  TensorCore
     97.2 ms  ColorVectorSpace 3.21% compilation time
      0.2 ms  DataValueInterfaces
      1.2 ms  DataAPI
      0.1 ms  IteratorInterfaceExtensions
      0.1 ms  TableTraits
     12.8 ms  Tables
      0.3 ms  Adapt
      2.6 ms  GPUArraysCore
     19.1 ms  StructArrays
     21.9 ms  IterTools
      2.1 ms  Extents
      0.8 ms  GeoInterface
      1.4 ms  EarCut_jll
    419.7 ms  GeometryBasics
     68.7 ms  FreeTypeAbstraction 11.94% compilation time
      0.9 ms  UnicodeFun
      0.2 ms  Scratch
      0.3 ms  RelocatableFolders
     84.4 ms  MathTeXEngine
      1.2 ms  FriBidi_jll
      1.0 ms  Libiconv_jll
      0.8 ms  Libffi_jll
      0.8 ms  XML2_jll
      1.1 ms  Gettext_jll
      0.7 ms  PCRE2_jll
      4.4 ms  Glib_jll
      0.5 ms  Pixman_jll
      0.3 ms  libpng_jll
      0.1 ms  Libuuid_jll
      0.3 ms  Expat_jll
      2.9 ms  Fontconfig_jll 69.27% compilation time
      0.5 ms  LZO_jll
      1.0 ms  Cairo_jll
      0.3 ms  Graphite2_jll
      0.7 ms  HarfBuzz_jll
      0.6 ms  libass_jll
      0.3 ms  libfdk_aac_jll
      0.5 ms  LAME_jll
      0.6 ms  Ogg_jll
      0.6 ms  libvorbis_jll
      0.5 ms  libaom_jll
      0.5 ms  x264_jll
      0.6 ms  x265_jll
      1.0 ms  OpenSSL_jll
      0.3 ms  Opus_jll
      4.8 ms  FFMPEG_jll
      0.2 ms  FFMPEG
     11.5 ms  Observables
      0.1 ms  SnoopPrecompile
     13.6 ms  ColorSchemes
    391.7 ms  PlotUtils
     48.7 ms  Parsers 8.67% compilation time
     19.0 ms  JSON
      0.2 ms  ColorBrewer
      3.5 ms  Packing
      0.1 ms  SignedDistanceFields
      7.6 ms  MakieCore
     68.2 ms  OffsetArrays
      0.5 ms  SortingAlgorithms
      7.1 ms  Missings
      0.3 ms  StatsAPI
     17.8 ms  StatsBase
     17.5 ms  PDMats
      0.6 ms  Rmath_jll
     45.7 ms  Rmath 84.48% compilation time
      0.2 ms  NaNMath
      1.8 ms  Calculus
     49.0 ms  DualNumbers
      0.8 ms  HypergeometricFunctions
      4.3 ms  StatsFuns
      2.4 ms  QuadGK
    143.5 ms  FillArrays
      1.1 ms  DensityInterface
    180.1 ms  Distributions
      6.6 ms  WoodburyMatrices
      0.3 ms  Requires
    215.5 ms  Ratios 93.28% compilation time (50% recompilation)
      0.2 ms  AxisAlgorithms
     35.5 ms  Interpolations 13.22% compilation time (100% recompilation)
      8.5 ms  AbstractFFTs
      0.9 ms  FFTW_jll
    392.9 ms  FFTW 3.15% compilation time
      2.0 ms  KernelDensity
      0.5 ms  isoband_jll
      0.1 ms  Isoband
      0.1 ms  PolygonOps
    105.1 ms  GridLayoutBase
    658.2 ms  FileIO 0.64% compilation time (100% recompilation)
      2.7 ms  IndirectArrays
      4.4 ms  LazyModules 68.02% compilation time
      0.4 ms  ImageIO
      1.7 ms  TriplotBase
      1.1 ms  Qhull_jll
      0.7 ms  QhullMiniWrapper_jll
      0.1 ms  MiniQhull
     25.1 ms  IntervalSets
      0.2 ms  Showoff
      0.5 ms  Formatting
      0.3 ms  Match
      3.5 ms  Animations
   5660.4 ms  Makie 0.17% compilation time
     21.7 ms  NetworkLayout 60.69% compilation time (44% recompilation)
    164.2 ms  GraphMakie
      5.8 ms  Combinatorics
    142.3 ms  OptimizedEinsum
      1.0 ms  CovarianceEstimation
     71.8 ms  NamedDims 5.64% compilation time (100% recompilation)
      1.5 ms  TupleTools
      0.2 ms  BatchedRoutines
      0.2 ms  BetterExp
      0.3 ms  Suppressor
     14.1 ms  OMEinsumContractionOrders 30.41% compilation time (100% recompilation)
     14.5 ms  OMEinsum 30.14% compilation time (100% recompilation)
     21.2 ms  SimpleWeightedGraphs
      5.9 ms  Pango_jll
      2.4 ms  Graphics
      3.0 ms  Cairo
      3.7 ms  Media 54.67% compilation time
    260.5 ms  Juno
      2.8 ms  JpegTurbo_jll
      1.6 ms  LERC_jll
      1.6 ms  Zstd_jll
      1.3 ms  Libtiff_jll
      1.5 ms  gdk_pixbuf_jll
      4.9 ms  Librsvg_jll
      3.1 ms  Rsvg 72.57% compilation time
    510.6 ms  Luxor 35.01% compilation time (32% recompilation)
     11.2 ms  Quac
    190.8 ms  Tenet