-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
Add a precompile statement to PlutoRunner
and some minor refactorings
#2039
Conversation
Try this Pull Request!Open Julia and type: julia> import Pkg
julia> Pkg.activate(temp=true)
julia> Pkg.add(url="https://github.com/fonsp/Pluto.jl", rev="rh/precompile-plutorunner")
julia> using Pluto |
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.
@rikhuijzer you should be interested by tooking a look at #1881 where this improvements could be more beneficial. PlutoRunner is currently included() in each notebook process in Loader.jl and I don't think precompile happens in this case?
@@ -176,7 +176,7 @@ replace_pluto_properties_in_expr(other; kwargs...) = other | |||
"Similar to [`replace_pluto_properties_in_expr`](@ref), but just checks for existance and doesn't check for [`GiveMeCellID`](@ref)" | |||
has_hook_style_pluto_properties_in_expr(::GiveMeRerunCellFunction) = true | |||
has_hook_style_pluto_properties_in_expr(::GiveMeRegisterCleanupFunction) = true | |||
has_hook_style_pluto_properties_in_expr(expr::Expr) = any(has_hook_style_pluto_properties_in_expr, expr.args) | |||
has_hook_style_pluto_properties_in_expr(expr::Expr)::Bool = any(has_hook_style_pluto_properties_in_expr, expr.args) |
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.
In which way does adding type assertion help? any
should be easy to infer.
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.
Normally, yes. But expr.args
is a Vector{Any}
:
julia> ex = :(1 + 1)
:(1 + 1)
julia> f(ex) = ex.args;
julia> @code_warntype f(ex)
MethodInstance for f(::Expr)
from f(ex) in Main at REPL[15]:1
Arguments
#self#::Core.Const(f)
ex::Expr
Body::Vector{Any}
1 ─ %1 = Base.getproperty(ex, :args)::Vector{Any}
└── return %1
which results in a Union{Missing, Bool}
instead of Bool
:
julia> g() = any(==("foo"), ex.args)
julia> @code_warntype g()
MethodInstance for g()
from g() in Main at REPL[17]:1
Arguments
#self#::Core.Const(g)
Body::Union{Missing, Bool}
1 ─ %1 = (==)("foo")::Base.Fix2{typeof(==), String}
│ %2 = Base.getproperty(Main.ex, :args)::Any
│ %3 = Main.any(%1, %2)::Union{Missing, Bool}
└── return %3
In general, you're right indeed.
julia h() = any(==("foo"), ["bar"]);
has return type Bool
.
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.
But does a return type help with inference? I thought that f(x) = z(x)::Bool
helps, but f(x)::Bool = z(x)
does not? Not sure why i think that
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.
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.
Sorry for late reply. I didn't see this one yet.
But does a return type help with inference? I thought that
f(x) = z(x)::Bool
helps, butf(x)::Bool = z(x)
does not? Not sure why i think that
Depends on where you care about the inference. In this case, the assertion on the method for has_hook_style_pluto_properties_in_expr
doesn't help to improve the running time of this method because the any
returns an Union{Missing,Bool}
and the type annotation on the function sets that to Bool
. So, no real gains there indeed. Instead the method might take slightly longer to run.
However, this may help a lot for places where the method is used, because thanks to the annotation, the type can be inferred which, in turn, may allow more code to be hit during precompilation.
In this case, I just added it because has_hook_style_pluto_properties_in_expr
must be a boolean at line 281. So, adding the annotation improves:
- code readability
- code inferability
- debugability because it fails at an earlier point. Namely, when an incorrect type is returned instead of when the incorrect type is passed to the
CachedMacroExpansion
struct.
Co-authored-by: Paul Berg <[email protected]>
Thanks a lot for the review Paul. Much appreciated ❤️
Yeah, I've waited now for a few weeks for that PR to make progress, but I figured that it's not going forward. Performance gains to |
I've added Before (
|
Could you also take a look at |
🎉 Awesome!! Did this really reduce |
Nope. Sorry voor de onduidelijke communicatie. Dat kan beter. In dit geval maar 20 MiB reducties helaas. Een gedeelte van de compile time is simpelweg verplaatst naar |
Some small changes to make the PlutoRunner slightly more snappy.
Changes:
Base.@kwdef
to make the code simpler and avoid having to compile a kwarg method.old_logger
a bit. This doesn't help in performance, but probably helps in readability.precompile
statement forrun_expression
.Time to first X
On Linux with Julia 1.8-beta3.
Before (
master
)After (this PR)