-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Base.precompile is highly effective - can it be auto-inserted? Documented? #12897
Comments
It's documented at http://docs.julialang.org/en/latest/stdlib/base/?highlight=precompile#Base.precompile but I guess you mean in the manual section on modules and precompilation. |
I have to say that it worries me to auto-generate The problem is that it pushes people to declare all arguments as concrete types to improve (first-time) performance, which is precisely the opposite of what they should be doing to have generic, Julian code. If this is a common issue that isn't solved by better documentation, maybe modules could push an |
just adding the |
Is there a way to get all the method signatures that were compiled? |
i tried making a demo of something similar a while back; i can't say if it even works anymore: 4802dcd |
Is it possible to precompile the functions encountered in |
It's interesting how many people started thinking about this all at once: I was about halfway towards a solution when I read this. I developed an approach that gets the compiler to dump the functions and types it's compiling, together with a measure of how long it spent compiling each one. See https://github.com/timholy/SnoopCompile.jl, and pull requests at GiovineItalia/Gadfly.jl#673 and GiovineItalia/Compose.jl#143. @vtjnash, probably the part I'd like the most feedback on is this bit. I'm not quite sure how to handle precompiles like this:
because Incidentally, of the ~2000 functions compiled by running https://github.com/timholy/SnoopCompile.jl/blob/03543b7124cc121a2e03e4f105eac73d74a9596a/examples/gadfly.jl#L14-L17, approximately half of them were in Base. So the cross-module thing is a pretty big deal. Those two PRs to Gadfly and Compose only included functions defined in those modules. |
Hah wow, we really are thinking about the same things! SnoopCompile looks fun, going to play with that. |
I didn't implement any cross-module caching for fear that it would slow down loading. |
Fine. So it's fair to say that, for now, this is basically the best we can do? |
For those interested, I posted some numbers over at GiovineItalia/Gadfly.jl#673 (comment) |
Amazing little tool @timholy. Thanks! |
Closing since we have |
This functionality is now available via In practice, after trying PrecompileSignatures.jl on bunch of packages, my takeaways is that the reduction in TTFX is somewhere in between actually running code and not running any code or So, the package is mostly useful for packages where running real-world workloads is infeasible due to side-effects or too many entrypoints. |
This is a very contrived reduced example to demonstrate my point, but I see the same effect in real JuMP and JuMPeR code.
Basically,
Base.precompile
is capable of slashing first-run times for functions by factors of 2 to 4 in my tests. For users at the REPL, or even just running small scripts, this has greatly improved the user experience. Getting a simple example is tricky, but considering the following code. Right at the bottom is a commented out call toBase.precompile
.Here is my test script:
Without
Base.precompile
With
Base.precompile
With is 3x speed up for the first run.
In this case, because all the arguments are specified, it would actually be possible to auto-generate that
Base.precompile
call. My first question/idea would be to auto-generate that call if the package is precompiled. Second, is documenting this (and the other great compile speed up trick, avoiding kwargs) desirable? I could see an argument for it not being a great idea to document due to how deep it gets into the internals and is something that can and hopefully will change over time.Here is the (contrived example) test module,
PrecompTest.jl
:The text was updated successfully, but these errors were encountered: