# Why is Julia's graphics system so slow?

**URL:** <https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750>\
**Category:** Performance\
**Tags:** plotting, ttfp\
**Created:** [September 25, 2021, 1:09pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750 "2021-09-25T13:09:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![aachener](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aachener/32/18112_2.png) [@aachener](https://discourse.julialang.org/u/aachener)\
**Post date:** [September 25, 2021, 1:09pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/1 "2021-09-25T13:09:30Z")

</div>

Hi, all,

I am relatively new to Julia, and am using Julia 1.6.2 as well as newest Plots.jl, pyplot.jl and Gadfly.jl. I am programming Julia using vs code extension.

I find that drawing charts and plots in Julia is particularly slow. Sometimes it takes me 10 seconds to draw a simple scatter plot with 200 points, both using Plots with pyplot back end or Gadfly. This is especially true when compared with base R or ggplot2 solutions.

I am just curious if it is my configuration which causes the time-consuming plotting process, or the graphics solutions in Julia is slow by nature? Is there any possible solutions to this issue?

Thanks.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [September 25, 2021, 1:31pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/2 "2021-09-25T13:31:26Z")

</div>

Do you experience this slowness only on the first invocation of a particular plot or always. The former is expected -it even has a name “time to first plot”- the latter should not happen.

The reduction of “time to first plot” is actively being worked on (yes it was a lot worse). It is caused by Julia compiling the needed functions on the fly (precompilation only does half of all the compile work).

If you search for “time to first plot” you will find a large amount of reading material…

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [September 25, 2021, 2:45pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/3 "2021-09-25T14:45:09Z")

</div>

If you google `time to first plot julia` you can get a lot more information on the topic, including all the work the devs are doing/have done to reduce this lag.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [September 25, 2021, 2:48pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/4 "2021-09-25T14:48:36Z")

</div>

Once I compiled a system image with StatsPlots, DataFrames, StatsBase, and such, it made time to first plot very small… See [A Julia DataAnalysis Sysimage from PackageCompiler It’s so easy you should do it too!](https://discourse.julialang.org/t/a-julia-dataanalysis-sysimage-from-packagecompiler-its-so-easy-you-should-do-it-too/68127)

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [September 25, 2021, 4:43pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/5 "2021-09-25T16:43:46Z")

</div>

You could also give VegaLite.jl a try, it has pretty good startup time.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [September 26, 2021, 4:31pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/6 "2021-09-26T16:31:21Z")

</div>

Hi @aachener,

### (Probable) Cause

From what I can tell, it appears the slowness comes from `VSCodeServer`’s `SVG` rendering facilities.

It is indeed more noticeable for scatter plots — or any plot that requires the rendering engine to generate alot of “plot markers”.

### Background

On my own system, it seems like a Plots.jl over VSCode plotting pane solution defaults to `SVG` (your solution may differ).

I have also noticed that, when generating scatter plots, the VSCode plot pane is _significantly slower_ than what I get for Plots.jl over _ **Jupyter notebooks** _ (in VSCode).

(You might also be interested in knowing Jupyter _also_ renders SVG by default, so the run times _should_ be comparable.)

### Quick test/workaround:

As a quick hack, you can remove the `"image/svg+xml"` mime from the list of mimes supported by the plotting pane (only affects current Julia session):

```julia
using Plots

###############################################################################
# ADD THIS BLOCK TO REMOVE SVG FROM LIST OF "DISPLAYABLE_MIMES":
pos = findfirst((x)->(x=="image/svg+xml"), VSCodeServer.DISPLAYABLE_MIMES)
if !isnothing(pos)
    popat!(VSCodeServer.DISPLAYABLE_MIMES, pos)
    println("Popped!")
end
###############################################################################

#A simple test plot here:
x = range(-100, 100, length=1001)
y = 3 * x .* x
p=plot(x, y, line=(2, :red), marker=(:hexagon, 20, 0.6, :green))
display(p)

```

### Follow-up

Does this help with your problem?

If so, maybe @davidanthoff / the VSCode team can propose a better permanent solution.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [September 26, 2021, 4:58pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/7 "2021-09-26T16:58:05Z")

</div>

Ah, very interesting! Could you open an issue over at the Julia extension repo?

My favorite tool to force a given MIME type is [https://github.com/tkf/DisplayAs.jl](https://github.com/tkf/DisplayAs.jl), that would probably also work here.

---

<div class="post-metadata">

**Author:** ![vancleve](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vancleve/32/4183_2.png) [@vancleve](https://discourse.julialang.org/u/vancleve)\
**Post date:** [September 26, 2021, 10:27pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/8 "2021-09-26T22:27:59Z")

</div>

I have noticed this too for SVG content plotted using julia and vscode, and its gotten worse recently for some reason. Plots are much more responsive in the plots pane if I first save the plot and then use `display("image/png", my_plot)`.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [September 27, 2021, 1:37am UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/9 "2021-09-27T01:37:26Z")

</div>

> [@davidanthoff](#):
>
> Could you open an issue over at the Julia extension repo?

I am guessing this is what you meant by “Julia extension repo”:

> <https://github.com/julia-vscode/julia-vscode/issues/2474>
>
> It appears that the SVG rendering facilities for VSCode's integrated plot pane i…s noticeably slow --- even when comparing to the inline plots rendered from the Jupyter extension.
> 
> The difference is obvious when using Plots.jl (for example) to plot over 1k points using markers (ex: scatterplot).
> 
> More details & sample code on discourse:
> \--\> https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [September 27, 2021, 1:42am UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/10 "2021-09-27T01:42:54Z")

</div>

> [@vancleve](#):
>
> display(“image/png”, my\_plot)

Ah yes. I forgot display allows you to specify the preferred mime-type.

Though I would suggest passing mime information as a `MIME` object — since I personally feel it is less ambiguous for julia dispatch:

```julia
display(MIME("image/png"), my_plot)

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [September 27, 2021, 8:34am UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/11 "2021-09-27T08:34:07Z")

</div>

This really isn’t an issue with VS Code, it’s an issue with large SVGs in general. IIRC Jupyter shows PNGs by default, which we should do as well, I suppose.

Try

```julia
julia> open("out.svg", "w") do io
         show(io, "image/svg+xml", Plots.scatter(1:10000, sin.(1:10000)))
       end; run(`firefox out.svg`)

```

for a pretty and very slow plot in your browser (the produced SVG is 1.8MiB big, so no wonder).

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 27, 2021, 9:07am UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/12 "2021-09-27T09:07:11Z")

</div>

> [@pfitzseb](#):
>
> IIRC Jupyter shows PNGs by default, which we should do as well, I suppose.

I don’t think that is true, at least not from my basic testing.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [September 28, 2021, 3:42am UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/13 "2021-09-28T03:42:23Z")

</div>

> [@pfitzseb](#):
>
> IIRC Jupyter shows PNGs by default

It doesn’t look like it on my system either (neither in the normal browser-based Jupyter — or the VSCode version):  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/2/7230f17dda57e869c832adbf68e59b151e12de86.png)

* * *

NOTE: You can see which mimes are evaluated by clicking on `[...]` on the LHS of your Jupyter plot:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/9/39a118d0108b1928e8e7a6243885a5882886f18d.png)

Instead, it appears I need to inhibit the “image/svg+xml” show function (as is done in PyPlot with `PyPlot.svg(false)`) to get PNG output by default.

> [@pfitzseb](#):
>
> shows PNGs by default, which we should do as well, I suppose

Yes. It is probably for the best.

I’m just wondering if that will negatively impact backends like Plotly that support interactive SVGs

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [October 14, 2021, 6:46pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/14 "2021-10-14T18:46:09Z")

</div>

I’m having this issue when plotting monte carlo simulations with more than 10^5 random points. I will really apreciate if someone knows how to configure the Plots output to png. SVG is really good for quality, but for some plots with huge random points there are huge performance loss. Vscode dont support large svg files.

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [October 14, 2021, 7:45pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/15 "2021-10-14T19:45:26Z")

</div>

You should be able to run:

```julia
using Plots
default(fmt=:png)

```

And this should create png output.

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [October 14, 2021, 8:28pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/16 "2021-10-14T20:28:02Z")

</div>

Thank you. That save my work here.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 14, 2021, 8:45pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/17 "2021-10-14T20:45:12Z")

</div>

> [@pfitzseb](#):
>
> IIRC Jupyter shows PNGs by default, which we should do as well, I suppose.

Last I checked, Jupyter shows SVG by default.

In PyPlot I worked around this by defining [`showable(::MIME"image/svg+xml", ::PyPlot.Figure) = false`](https://github.com/JuliaPy/PyPlot.jl/blob/fe49cdf33e229b3ebf82b0a01ba5503291909d89/src/PyPlot.jl#L93) by default (which prevents that MIME type from being sent to Jupyter, even though the SVG `show` method exists), with a [setting to enable SVG output if desired](https://github.com/JuliaPy/PyPlot.jl#svg-output-in-ijulia)

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [October 14, 2021, 8:46pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/18 "2021-10-14T20:46:31Z")

</div>

even with png, vscode hangs ☹ Too much memory for that

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/6/1642aa727aaf53364a32921d6f71a3e692cf18ef.png)

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [October 14, 2021, 8:50pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/19 "2021-10-14T20:50:19Z")

</div>

Pluto can plot this withou any issues.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/f/0f5e5dcb233215935d2355a4c6b08011531bdd30.png)

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [October 14, 2021, 8:51pm UTC](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750/20 "2021-10-14T20:51:51Z")

</div>

By any chance are there still old svg plots in the VSCode plot pane? Like if you click the arrows, can you see the plots you made before changing the output to png? If so, try closing them.

[Next page](https://discourse.julialang.org/t/why-is-julias-graphics-system-so-slow/68750.md?page=2)
