Why is plotting with GR faster when using GR_jll and `@ccall` directly

Why is plotting with GR faster when using GR_jll and @ccall directly? @jheinen

using GR_jll

   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.0 (2021-03-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> @time begin
           @time using GR_jll
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           gr = :libgr
           @time @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall gr.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall gr.gr_updatews()::Nothing
       end
  0.681576 seconds (292.18 k allocations: 19.435 MiB, 0.77% gc time, 0.48% compilation time) # using GR_jll
GKS: file open error (/workspace/destdir\FONTS\GKSFONT.DAT)
open: No such file or directory
  0.033260 seconds (3.92 k allocations: 223.016 KiB, 30.53% compilation time) # gr.gr_polyline
  0.013906 seconds (3.53 k allocations: 203.047 KiB, 63.91% compilation time) # gr.gr_axes
  0.000004 seconds (6 allocations: 192 bytes) # gr.gr_updatews
  0.803224 seconds (416.77 k allocations: 27.419 MiB, 0.66% gc time, 2.78% compilation time) # begin ... end

versus

using GR

   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.0 (2021-03-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> @time begin
           @time using GR
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           gr = :libgr
           @time @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall gr.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall gr.gr_updatews()::Nothing
       end
  0.237283 seconds (63.35 k allocations: 5.483 MiB, 1.55% compilation time) # using GR
  2.321641 seconds (3.92 k allocations: 223.016 KiB, 0.46% compilation time) # gr.gr_polyline
  0.007653 seconds (3.53 k allocations: 203.047 KiB, 98.55% compilation time) # gr.gr_axes
  0.000056 seconds (6 allocations: 192 bytes) # gr.gr_updatews
  2.638014 seconds (187.92 k allocations: 13.304 MiB, 0.83% compilation time) # begin... end
julia> versioninfo()
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

GR.__init__ changes Environmental Variables

I took a look at GR.jl’s __init__ and I noticed it set some environmental variables:

julia> orgENV= copy(ENV);

julia> using GR

julia> setdiff(ENV,orgENV)
4-element Vector{Pair{String, String}}:
      "GKS_ENCODING" => "utf8"
      "GKS_FONTPATH" => "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"
 "GKS_USE_CAIRO_PNG" => "true"
             "GRDIR" => "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"

Setting environmental variable results in slowdown

julia> begin
           ENV["GRDIR"] = "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"
           ENV["GKS_FONTPATH"] = "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"
           ENV["GKS_ENCODING"] = "utf8"
           ENV["GKS_USE_CAIRO_PNG"] = "true"
       end
"true"

julia> @time begin
           @time using GR_jll
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           gr = :libgr
           @time @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall gr.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall gr.gr_updatews()::Nothing
       end
  0.741127 seconds (292.18 k allocations: 19.435 MiB, 0.92% gc time, 0.46% compilation time)
  2.322584 seconds (3.92 k allocations: 223.016 KiB, 0.46% compilation time)
  0.012314 seconds (3.53 k allocations: 203.047 KiB, 99.16% compilation time)
  0.000056 seconds (6 allocations: 192 bytes)
  3.149256 seconds (416.77 k allocations: 27.419 MiB, 0.22% gc time, 0.83% compilation time)

I actually get a blank plot at the end of this, but now it takes more than two seconds to call gr.gr_polyline.

Setting ENV[“GRDIR”] is sufficient to cause the slowdown

julia> begin
           ENV["GRDIR"] = "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"
       end
"C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"

julia> @time begin
           @time using GR_jll
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           gr = :libgr
           @time @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall gr.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall gr.gr_updatews()::Nothing
       end
  0.678470 seconds (292.17 k allocations: 19.434 MiB, 0.61% compilation time)
  2.325419 seconds (3.92 k allocations: 223.016 KiB, 0.45% compilation time)
  0.025172 seconds (3.53 k allocations: 203.047 KiB, 99.14% compilation time)
  0.000110 seconds (6 allocations: 192 bytes)
  3.106615 seconds (416.75 k allocations: 27.301 MiB, 1.28% compilation time)

Setting other environmental variables does not result in a slowdown

julia> begin
           #ENV["GRDIR"] = "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"
           ENV["GKS_FONTPATH"] = "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"
           ENV["GKS_ENCODING"] = "utf8"
           ENV["GKS_USE_CAIRO_PNG"] = "true"
       end
"true"

julia> @time begin
           @time using GR_jll
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           gr = :libgr
           @time @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall gr.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall gr.gr_updatews()::Nothing
       end
  0.672858 seconds (292.17 k allocations: 19.434 MiB, 0.46% compilation time)
  0.027195 seconds (3.92 k allocations: 223.016 KiB, 38.21% compilation time)
  0.014427 seconds (3.53 k allocations: 203.047 KiB, 57.92% compilation time)
  0.000004 seconds (6 allocations: 192 bytes)
  0.788307 seconds (416.75 k allocations: 27.350 MiB, 2.77% compilation time)

Package versions

Also here are the versions I am using:

(@v1.6) pkg> st GR
      Status `C:\Users\kittisopikulm\.julia\environments\v1.6\Project.toml`
  [28b8d3ca] GR v0.55.0

(@v1.6) pkg> st GR_jll
      Status `C:\Users\kittisopikulm\.julia\environments\v1.6\Project.toml`
  [d2c73de3] GR_jll v0.56.1+0

Why not using the variable libGR defined by both packages instead of using :libgr which doesn’t actually work?

julia> using GR

julia> x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7];

julia> gr = :libgr;

julia> @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
ERROR: could not load library "libgr"
libgr.so: cannot open shared object file: No such file or directory
Stacktrace:
 [1] top-level scope
   @ ./REPL[6]:1

Also, I can’t reproduce your timings:

julia> @time begin
           @time using GR: libGR
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           @time @ccall libGR.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall libGR.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall libGR.gr_updatews()::Nothing
       end
  0.146296 seconds (57.11 k allocations: 5.017 MiB, 2.73% compilation time)
  0.315977 seconds (4.04 k allocations: 228.562 KiB, 4.74% compilation time)
  0.011421 seconds (3.62 k allocations: 206.984 KiB, 98.81% compilation time)
  0.000037 seconds (6 allocations: 192 bytes)
  0.574396 seconds (182.01 k allocations: 12.853 MiB, 5.27% compilation time)
julia> @time begin
           @time using GR_jll: libGR
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           @time @ccall libGR.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall libGR.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall libGR.gr_updatews()::Nothing
       end
  0.115333 seconds (198.66 k allocations: 15.067 MiB, 3.71% compilation time)
GKS: file open error (/workspace/destdir/fonts/gksfont.dat)
open: No such file or directory
GKS: X11 support not compiled in
  0.016375 seconds (4.04 k allocations: 228.562 KiB, 96.41% compilation time)
  0.010168 seconds (3.62 k allocations: 206.984 KiB, 98.54% compilation time)
  0.000006 seconds (6 allocations: 192 bytes)
  0.246544 seconds (323.58 k allocations: 22.975 MiB, 12.20% compilation time)

It worked for me, but here we go:

Using GR; with gr = GR.libGR

julia> @time begin
           @time using GR
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           gr = GR.libGR
           @time @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall gr.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall gr.gr_updatews()::Nothing
       end
  0.244950 seconds (65.85 k allocations: 5.683 MiB, 1.14% compilation time)
  2.325786 seconds (3.92 k allocations: 223.016 KiB, 0.45% compilation time)
  0.021604 seconds (3.53 k allocations: 203.047 KiB, 99.28% compilation time)
  0.000073 seconds (6 allocations: 192 bytes)
  2.664028 seconds (190.41 k allocations: 13.505 MiB, 1.30% compilation time)

using GR_jll; gr = GR_jll.libGR

julia> @time begin
           @time using GR_jll
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           gr = GR_jll.libGR
           @time @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall gr.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall gr.gr_updatews()::Nothing
       end
  0.677641 seconds (292.17 k allocations: 19.434 MiB, 0.96% gc time, 0.48% compilation time)
GKS: file open error (/workspace/destdir\FONTS\GKSFONT.DAT)
open: No such file or directory
  0.026946 seconds (3.92 k allocations: 223.016 KiB, 37.90% compilation time)
  0.013350 seconds (3.53 k allocations: 203.047 KiB, 60.41% compilation time)
  0.000006 seconds (6 allocations: 192 bytes)
  0.790913 seconds (416.76 k allocations: 27.418 MiB, 0.82% gc time, 2.72% compilation time)
julia> begin
           #ENV["GRDIR"] = "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"
           ENV["GKS_FONTPATH"] = "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"
           ENV["GKS_ENCODING"] = "utf8"
           ENV["GKS_USE_CAIRO_PNG"] = "true"
       end
"true"

julia> @time begin
           @time using GR_jll
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           gr = GR_jll.libGR
           @time @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall gr.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall gr.gr_updatews()::Nothing
       end
  0.677451 seconds (292.17 k allocations: 19.434 MiB, 0.82% gc time, 0.47% compilation time)
  0.034265 seconds (3.92 k allocations: 223.016 KiB, 32.98% compilation time)
  0.012879 seconds (3.53 k allocations: 203.047 KiB, 60.35% compilation time)
  0.000006 seconds (6 allocations: 192 bytes)
  0.797809 seconds (416.76 k allocations: 27.419 MiB, 0.69% gc time, 2.79% compilation time)

using GR_jll; gr = GR_jll.libGR; Setting GRDIR environment variable

julia> begin
           ENV["GRDIR"] = "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"
           #ENV["GKS_FONTPATH"] = "C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"
           #ENV["GKS_ENCODING"] = "utf8"
           #ENV["GKS_USE_CAIRO_PNG"] = "true"
       end
"C:\\Users\\kittisopikulm\\.julia\\packages\\GR\\BwGt2\\src\\..\\deps\\gr"

julia> @time begin
           @time using GR_jll
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           gr = GR_jll.libGR
           @time @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall gr.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall gr.gr_updatews()::Nothing
       end
  0.680800 seconds (292.17 k allocations: 19.419 MiB, 0.78% gc time, 0.48% compilation time)
  2.323178 seconds (3.92 k allocations: 223.016 KiB, 0.46% compilation time)
  0.025672 seconds (3.53 k allocations: 203.047 KiB, 99.27% compilation time)
  0.000111 seconds (6 allocations: 192 bytes)
  3.104938 seconds (416.76 k allocations: 27.403 MiB, 0.17% gc time, 1.27% compilation time)

What happens if I just delete the GRDIR environmental variable?

Deleting GRDIR environmental variable, using @ccall

   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.0 (2021-03-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> @time begin
           @time using GR
           delete!(ENV, "GRDIR")
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           gr = GR.libGR
           @time @ccall gr.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
           @time @ccall gr.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
           @time @ccall gr.gr_updatews()::Nothing
       end
  0.243086 seconds (65.84 k allocations: 5.586 MiB, 1.17% compilation time)
  0.023278 seconds (3.92 k allocations: 223.016 KiB, 44.35% compilation time)
  0.011711 seconds (3.53 k allocations: 203.047 KiB, 76.49% compilation time)
  0.000006 seconds (6 allocations: 192 bytes)
  0.351513 seconds (190.47 k allocations: 13.412 MiB, 6.29% compilation time)

Using GR with low level calls, deleting the GRDIR environmental variable

julia> @time begin
           @time using GR
           delete!(ENV, "GRDIR")
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           @time GR.polyline(x,y)
           @time GR.axes(0.2, 0.2, 0, 0, 1, 1, -0.01)
           @time GR.updatews()
       end
  0.244590 seconds (65.84 k allocations: 5.667 MiB, 1.18% compilation time)
  0.016647 seconds (4.20 k allocations: 239.353 KiB, 30.95% compilation time)
  0.010972 seconds (7.61 k allocations: 439.749 KiB, 45.82% compilation time)
  0.002287 seconds (499 allocations: 36.671 KiB, 98.66% compilation time)
  0.347401 seconds (195.32 k allocations: 13.777 MiB, 4.41% compilation time)

This works, and I get my plot:

Next, I wondered what if I combined this with PackageCompiler.jl and just used plot:

PS C:\Users\kittisopikulm> julia -J .\sys_plots.dll                                                                                    _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.0 (2021-03-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> @time begin
           @time using GR
           # delete!(ENV, "GRDIR")
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           plot(x,y)
       end
  0.000945 seconds (811 allocations: 59.977 KiB, 211.65% compilation time)
  2.387969 seconds (125.19 k allocations: 8.038 MiB, 0.08% compilation time)

julia> exit()
PS C:\Users\kittisopikulm> julia -J .\sys_plots.dll
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.0 (2021-03-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> @time begin
           @time using GR
           delete!(ENV, "GRDIR")
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           plot(x,y)
       end
  0.001334 seconds (811 allocations: 59.977 KiB, 213.11% compilation time)
  0.096102 seconds (125.26 k allocations: 8.043 MiB, 2.96% compilation time)

This works, but in this case I’m missing my axis labels:

image

Maybe this is a Windows issue?

Above, GR.gr_provider was actually “GR”. This means GR.jl was not actually using GR_jll at all, but rather downloading GR itself. This is not surprising since GR.jl’s use of BinaryBuilder and GR_jll was disabled 5 days ago:

I can force the use of GR_jll by

  1. $env:JULIA_GR_PROVIDER="BinaryBuilder" in PowerShell
  2. using Pkg; Pkg.build("GR")

Attempting to use GR after this produces errors of this sort:

julia> @time begin
                  @time using GR: libGR, GR_jll
                  x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
                  @time @ccall libGR.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
                  @time @ccall libGR.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
                  @time @ccall libGR.gr_updatews()::Nothing
              end
  0.808025 seconds (355.11 k allocations: 24.770 MiB, 0.39% compilation time)
connect: No error
GKS: can't connect to GKS socket application

GKS: Open failed in routine OPEN_WS
GKS: GKS not in proper state. GKS must be either in the state WSOP or WSAC in routine ACTIVATE_WS
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
 23.070139 seconds (3.92 k allocations: 223.016 KiB, 0.05% compilation time)
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
  0.036716 seconds (3.53 k allocations: 203.047 KiB, 69.96% compilation time)
  0.000008 seconds (6 allocations: 192 bytes)
 23.993162 seconds (479.67 k allocations: 32.592 MiB, 0.17% compilation time)

This problem is due to how the GKS_QT environmental variable is constructed which attempts to set the PATH and execute a command.

The following resolves the GKS state issue by setting the PATH through Julia first.

julia> @time begin
                  @time using GR: libGR, GR_jll
                  ENV["PATH"] = GR_jll.LIBPATH[] * ";" * ENV["PATH"]
                  ENV["GKS_QT"] = GR_jll.gksqt_path
                  x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
                  @time @ccall libGR.gr_polyline(6::Cint, pointer(x)::Ptr{Float64}, pointer(y)::Ptr{Float64})::Nothing
                  @time @ccall libGR.gr_axes(0.2::Float64, 0.2::Float64, 0::Float64, 0::Float64, 1::Cint, 1::Cint, (-0.01)::Float64)::Nothing
                  @time @ccall libGR.gr_updatews()::Nothing
              end
  0.789749 seconds (355.13 k allocations: 24.924 MiB, 0.73% gc time, 0.40% compilation time)
  2.325438 seconds (3.92 k allocations: 223.016 KiB, 0.54% compilation time)
  0.013462 seconds (3.53 k allocations: 203.047 KiB, 98.92% compilation time)
  0.000089 seconds (6 allocations: 192 bytes)
  3.203867 seconds (479.71 k allocations: 32.768 MiB, 0.18% gc time, 0.91% compilation time)

However, the we again see the time lag.

By deleting ENV["GRDIR"] above, I believe the main effect was to change the practical workstation type, which can be viewed in the help file of GR.openws. In my case, we can set ENV["GKSWSTYPE"] = 41 for Windows GDI to get a fairly fast plot without using a systems image.

   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.0 (2021-03-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> @time begin
           using GR
           ENV["GKSWSTYPE"] = 41
           x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
           GR.polyline(x,y)
           GR.axes(0.2, 0.2, 0, 0, 1, 1, -0.01)
           GR.updatews()
       end
  0.855669 seconds (412.19 k allocations: 28.426 MiB, 0.63% gc time, 0.37% compilation time)