-
-
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
__precompile__(isprecompilable) function for automated opt-in to module precompilation #12491
Conversation
Very nice resolution---good suggestion @ScottPJones! |
😀 Finally I've managed to do something right around here! Thanks! (maybe this is my start on working off my immense bikeshedding debt!) |
Of, course, this wouldn't be a proper Julia PR if we don't immediately commence a huge bikeshed over spelling. Options:
Plus many more-verbose options. |
Happy to start the ball rolling. What about something like Maybe just a more explicit |
@mbauman, I avoided I avoided |
(I chose a verb over an adjective because |
|
@ssfrr, no, because that incorrectly implies that it will compile an arbitrary file argument, whereas this only forces the compilation of the file(s) where it is executed (and technically only as a side effect of import; the |
|
@davidagold, yes, |
|
👍 for |
@stevengj Me too. The underscore makes quite a difference in readability. |
@StefanKarpinski, yes, |
What about just expressing that fact? +:100: for the functionality (and all your work this week), and I think the |
Argh, I hate to bring this up, but I don't think "compile" is really the right word here at all. |
Also, sorry to contribute more to bikeshedding, but "me" seems a bit too cute. The code is not a person. |
@ScottPJones, I agree that technically what is happening is that it is caching the compiled version. But I think that in practice most people will think of it in shorthand as "compiling" the code. Anyway DOUBLE UNDERSCORES will warn the reader that something funky is going on. |
I think that they already know it is compiling the code, and in fact, |
|
+1 to |
Someone needs to bump appveyor. |
|
I spent about ten minutes on trying to get this build to go again, but the AppVeyor interface has defeated me. It refuses to restart the build, telling me to contact support. The support contact page requires you authenticate separately from the main app, but only supports password and Google auth, while my account is setup to authenticate with GitHub – which isn't an option. I also can't figure out where in the interface one goes to give others admin rights to the repo or how to create an email / password login (changing the password requires entering an old password, which I don't have). |
Of course, I also think that |
@StefanKarpinski, this is appveyor/ci#353, and @tkelman was able to force a new build number in some other PRs IIRC. |
I'm fine with |
👍 to @stevengj's suggestion, succinct and accurate! |
(Of course, there already is a |
(nvm, I see the error message. maybe try a force push now that the build number has been bumped a few times?) |
I've reset that stuck build. When the build version collision is happening we are seeing database timeouts. We are working to resolve this issue. |
I'll do a force push in a minute. |
…le precompilation on import (closes JuliaLang#12462)
At the risk of getting pelted with rotten virtual 🍅s, what about the following minor changes: |
See my above comment on adjectives. I'm not too concerned about Base.compilecache or whatever, since calling it should be almost never needed. We might even remove it from the manual. |
Maybe
|
I don't hear a clamor of support for a more verbose spelling. |
My vote: go with the current version.
|
Smack that big ol' green button @stevengj |
__precompile__(isprecompilable) function for automated opt-in to module precompilation
Great job, @stevengj! |
👍 I think brand new functions need to have signatures manually added to the RST docs at the moment for |
One small problem I foresee: because compilation is slower than loading the package if you only plan to do it once, developers actively working on a package are likely to (1) delete the Seems like a small price 😄 and not very different from the other "oops"es you can make (I'm surprised I don't have more |
@timholy, it would be trivial to add a "development" global flag that disables |
I'd say let's first see how bad a problem it is. |
Also, realize that if you are working on a module, only that module itself will be recompiled when you change the module's files — imported modules (assuming they haven't changed) are not recompiled. So the recompile is often considerably faster than the initial |
Oh, definitely, and the main reason I wanted precompilation so much 😄. But I'm a greedy bastard, and have already discovered I can make life just a little better by temporarily disabling it for the specific package I happen to be hacking on (at least until I finish making all my stupid mistakes). |
I was concerned about this too originally, but found the impact to be less than I expected when I was just working on Gtk.jl and ZMQ.jl. Having the cache always up-to-date, without needing to actively think about it, seems like such a huge improvement. I believe the developer time penalty is only about 25% (cache-load time seems to be about 10% of the load time, but the dependencies need to be loaded in both processes), on average, to build a new cache for the module – time that I felt was now being saved whenever I moved on to the usages of the module (e.g. today it was for IJulia). As a future optimization, if we can implement file-system locking, then we could turn on parallel precompilation. I think that while it would be somewhat faster to have it turned off for rapid iteration development, like the JIT, it shouldn't end up mattering enough to warrant much attention. |
This addresses #12462 by adding a new function
__precompile__(isprecompilable::Bool=true)
:__precompile__()
(typically at the top of the file before themodule
statement), then it will be automatically precompiled when it is imported for the first time (and thereafter will be automatically recompiled thanks to automatic recompilation of stale cache files #12458). Technically,__precompile__(true)
throws an exception if the file is included in a non-precompile Julia process.__precompile__(false)
, then it will throw an exception during precompilation. This way, if a module is known to be unsafe to precompile, you can prevent the user from precompiling it accidentally (e.g. by importing it into another module that is being compiled).VERSION >= v"0.4-" && __precompile__()
. We should also put__precompile__
into Compat for completeness, but it is nice to be able to put__precompile__()
before themodule ... end
in order to prevent the module from being parsed oreval
-ed (even partially) when we are detecting precompilability.Base.compile(mod)
(which should now be rarely needed by users) is renamed toBase.compilecache(mod)
to better describe its function.Thanks to @ScottPJones for his suggestion. This turned out to be much cleaner than the
#pragma
approach in #12475, with no loss of functionality.