JuliaLang / IJulia.jl

Julia kernel for Jupyter
MIT License
2.8k stars 413 forks source link

much slower than terminal #1005

Closed XinyuWuu closed 1 month ago

XinyuWuu commented 3 years ago

When I use IJulia with a costom sysimage created by PackageCompiler.jl, the code runs much slower.

my kernel:

{
  "display_name": "Julia costom sysimage 1.6.1",
  "argv": [
    "/home/wuxinyu/Programs/julia/bin/julia",
    "-i",
    "--color=yes",
    "--sysimage=/home/wuxinyu/.julia/environments/v1.6/mysys.so",
    "/home/wuxinyu/.julia/packages/IJulia/e8kqU/src/kernel.jl",
    "{connection_file}"
  ],
  "language": "julia",
  "env": {},
  "interrupt_mode": "signal"
}

my test code:

using Gadfly, RDatasets
set_default_plot_size(21cm, 8cm)

p1 = plot(dataset("HistData","DrinksWages"), x="Wage", y="Drinks",
    shape=[Shape.square], Scale.y_log10)

aww, mws = dataset("MASS", "Animals"), dataset("quantreg", "Mammals")
p2 = plot( layer(aww, x=:Body, y=:Brain, shape=["Brain weight"]),
    layer(mws, x=:Weight, y=:Speed, shape=["Run speed"]),
    Scale.x_log10, Scale.y_log10, Guide.xlabel("Body weight"),
    Guide.ylabel("Brain weight and Run speed"),
    Theme(point_shapes=[Shape.circle, Shape.star1], alphas=[0.0],
        discrete_highlight_color=identity) )
hstack(p1, p2)

When in the terminal it runs extremely fast, but in the notebook, it takes 12s. In both case the code is the first time been executed.

twavv commented 3 years ago

This is just a guess, but could it be that using IJulia causes precompilation invalidations? Did you build the sysimage with IJulia? (If not, does building with IJulia included fix the issue?)

XinyuWuu commented 3 years ago
PackageCompiler.create_sysimage([:Gadfly,:DataFrames,:Colors,:Dates,:OhMyREPL,:ColorSchemes,:Distributions,:RDatasets,:Compose,:Random,:CSV,:GLPK,:HDF5,:IterTools,:JSON,:JuMP,:Measures,:RData,:XLSX,:Printf,:Statistics,:CategoricalArrays,:IJulia], precompile_statements_file="compiler_trace.jl",sysimage_path="mysys.so")

It is my build command. I have include the IJulia, but it is still much slower. And I have test not only one piece of code, but more ploting code, so I don't think it is a guess.

IJulia did not causes precompilation invalidations, it runs faster than before(without precompiled sysimage), but it is much slower than terminal.

I think IJulia definitely slow down the speed in some way, but I don't know the reasons.

terasakisatoshi commented 3 years ago

I think you also need precompile display function that is used by IJulia. My repository https://github.com/terasakisatoshi/sysimage_creator will help you. It will reduce time to initialize Jupyter Kernel and plot for the first time. Have a try.

nilshg commented 1 month ago

This can be closed.