Skip to content
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

Set Base.Experimental.@max_methods 1 #2068

Merged
merged 1 commit into from
Apr 27, 2022
Merged

Set Base.Experimental.@max_methods 1 #2068

merged 1 commit into from
Apr 27, 2022

Conversation

rikhuijzer
Copy link
Collaborator

@rikhuijzer rikhuijzer commented Apr 27, 2022

From Julia 1.8 onwards, there is the Base.Experimental.@max_methods setting (JuliaLang/julia#43370). See especially JuliaLang/julia#43370 (comment) for an example of what this setting does.

In Pluto.jl, I've seen a bunch of methods showing inferred fields as Union{Vector{Tuple}, Vector{Tuple{Any}}} or other unhelpful types. It's better if the compiler would waste time on that, just infer Any and compile a runtime dispatch.

Benchmarks

Below are the benchmarks for compilation time and some random extra benchmarks to verify that running time isn't seriously affected. All benchmarks on Julia 1.8-beta3:

Without @max_methods (main)

 Section                        ncalls     time    %tot     alloc    %tot
 ────────────────────────────────────────────────────────────────────────
 import Pluto                        1    580ms    1.9%   77.7MiB    2.9%
 compiletimes.jl                     1    29.8s   98.1%   2.50GiB   97.1%
   PlutoRunner.run_expression        1    1.48s    4.9%   86.8MiB    3.3%
   SessionActions.open               1    18.5s   60.7%   1.43GiB   55.6%
   Pluto.run                         1    4.85s   15.9%    558MiB   21.2%
 ──────────────────────────────────────────────────────────────────────── 
julia> @btime Pluto.PlutoRunner.format_output((a=[1,2], c=Dict("d"=>(5,6,true))));
  845.114 μs (1638 allocations: 104.02 KiB)

julia> @btime Pluto.PlutoRunner.try_macroexpand(Main, Pluto.uuid1(), Expr(:toplevel, :(import Base)));
  16.821 μs (195 allocations: 7.42 KiB)

With @max_methods (this PR)

 Section                        ncalls     time    %tot     alloc    %tot
 ────────────────────────────────────────────────────────────────────────
 import Pluto                        1    561ms    1.9%   74.7MiB    3.0%
 compiletimes.jl                     1    29.0s   98.1%   2.38GiB   97.0%
   PlutoRunner.run_expression        1    1.42s    4.8%   79.4MiB    3.2%
   SessionActions.open               1    17.6s   59.6%   1.31GiB   53.4%
   Pluto.run                         1    4.67s   15.8%    562MiB   22.4%
 ────────────────────────────────────────────────────────────────────────  
julia> @btime Pluto.PlutoRunner.format_output((a=[1,2], c=Dict("d"=>(5,6,true))));
  846.670 μs (1638 allocations: 104.02 KiB)

julia> @btime Pluto.PlutoRunner.try_macroexpand(Main, Pluto.uuid1(), Expr(:toplevel, :(import Base)));
  15.118 μs (166 allocations: 6.83 KiB)

@github-actions
Copy link
Contributor

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/max_methods")
julia> using Pluto

@rikhuijzer rikhuijzer merged commit dcd5101 into main Apr 27, 2022
@rikhuijzer rikhuijzer deleted the rh/max_methods branch April 27, 2022 18:27
@fonsp fonsp added the backend Concerning the julia server and runtime label Apr 29, 2022
@pankgeorg
Copy link
Collaborator

Let's also try to set this in PlutoRunner and test how it will go!

@rikhuijzer
Copy link
Collaborator Author

Let's also try to set this in PlutoRunner and test how it will go!

I just did and couldn't spot any gain in the number of allocations for the compilation time benchmark. I suspect that it is because there are no cases where max methods is an issue or because the difference is so small that it is hard to spot or it is already done via the global setting for the package. I'm not gonna dive deeper into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Concerning the julia server and runtime performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants