-
-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce time to first plot by precompiling functions #2250
Conversation
@@ -1,3 +1,658 @@ | |||
function _precompile_() | |||
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing | |||
precompile(Tuple{typeof(Plots.gr_set_gradient), Plots.Series}) | |||
precompile(Tuple{typeof(Plots.gr_display), Plots.Subplot{Plots.GRBackend}, Measures.Length{:mm, Float64}, Measures.Length{:mm, Float64}, Array{Float64, 1}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so there's no need to split gr_display?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to try that, but thought I'd put what I've got up.
By the way, when I run the examples, I see lots of |
That's from StatsPlots.jl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
What's the process for maintaining the precompile file? When functions in the list change will it fail, so it needs to be re-ran? |
The PR includes a |
I confirm I observed the same speedup as well. |
I get this error as well on the follwoing setup
The errors are always preceeded by an
which seems to happen outside julia since julia happily continues on, without plotting. I can continue plotting again if I call |
A couple of notes from my own experience:
That said, the proof is in the pudding, and if this is contributing towards a reduction in plotting time, that's a great thing! |
By how much does this increase load times? |
For me, I'll also note, that @yhls gave me a few more precompiles for Base and GR.jl. With those I am able to get the first plot in 8.3s. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @yhls! This is so amazing!
test/generateprecompiles.jl
Outdated
@@ -0,0 +1,26 @@ | |||
# To figure out what should be precompiled, run this script, then move |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move this file to deps instead of test as @ViralBShah suggested?
Would it make sense to have a Project.toml in deps then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I thought Project.toml files were just for the top level of a project/package, or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For someone without StatsPlots or RDataSets installed the test_examples 25 and 30 would still fail here. Furthermore, example 6 fails if FileIO is not installed.
Hence, I was thinking we could add a Project.toml with these dependencies, so people could just do pkg> activate deps
before running the generateprecompiles.jl script.
However, this does not work anyway, because in @snoopc
a new julia process with the default project is started.
Maybe we should add a comment here that StatsPlots, RDataSets, FileIO and (obviously) SnoopCompile have to be installed to run this script.
I just saw, that there are only Plots.jl functions checked into the precompile file, so I guess that will be much lesser of an issue... |
50e4c47
to
05eed0f
Compare
|
I think you might want to more carefully measure the performance effect here. Earlier this year, I submitted a PR to Gadfly to use snoopcompile-generated precompile statements. What I found there was that while it did reduce the See the graphs at GiovineItalia/Gadfly.jl#1280 (comment) and GiovineItalia/Gadfly.jl#1280 |
Thanks for the hint, @non-Jedi ! |
Am I right that Revise does not work anymore for Plots development with these changes? That's pretty annoying. Is there anything that can be done about that? |
Aside from timholy/Revise.jl#316 (and fix coming in timholy/Revise.jl#395), there is no real reason it shouldn't work. The backend files that don't get automatically
|
I should note that there are accompanying additions to precompile statements in Base and GR.jl that will give another slight bump in time to first plot. My timings for increased load time of Plots.jl from 2 to 4 seconds included these additional precompiles in GR.jl, and the Base system image having the additional precompiles. @yhls should be able to say more. |
Thanks a lot for the hints for conditionally loaded backends @timholy ! I just tested again, and you are right, Revise works with just fine with Plots. I'm not sure what the issue was two days ago. |
It turns out that using precompile statements generated by SnoopCompile.jl helps quite a lot! For example, this PR reduces the time to evaluate
display(plot(rand(10), rand(10)))
for the first time from ~22 seconds to ~12 seconds for me.To generate
precompile.jl
, which is currently unused, I've included a script that uses SnoopCompile to log method compilations that take place while running the examples on the GR backend.