Skip to content

Commit

Permalink
inference: add benchmark target to check benefit of method match cache
Browse files Browse the repository at this point in the history
This benchmark target corresponds to JuliaLang/julia/pull/46535.

`method_match_cache` contains many artificially generated broadcasting
operations, that will lead to constant propagations and accompanying
method match analysis on call sites with same abstract signatures, e.g.
- `Tuple{typeof(convert), Type{Int64}, Int64}`
- `Tuple{typeof(convert), Type{Float64}, Float64}`

Since we currently don't cache method match result for abstract call
signatures on the level of the runtime system, we can obtain the best
performance if we cache such abstract method match results on Julia level,
that will be revived by JuliaLang/julia/pull/46535.
  • Loading branch information
aviatesk committed Aug 30, 2022
1 parent f68f9ee commit 1e8a1c4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/inference/InferenceBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ let # see https://github.com/JuliaLang/julia/pull/45276
$ex
end
end
let # see https://github.com/JuliaLang/julia/pull/46535
n = 100
ex = Expr(:block)
var = gensym()
push!(ex.args, :(y = sum(x)))
for i = 1:n
push!(ex.args, :(x .= $(Float64(i))))
push!(ex.args, :(y += sum(x)))
end
push!(ex.args, :(return y))
@eval global function method_match_cache(x)
$ex
end
end

const SUITE = BenchmarkGroup()

Expand All @@ -195,6 +209,7 @@ let g = addgroup!(SUITE, "abstract interpretation")
g["construct_ssa!"] = @benchmarkable abs_call(CC.construct_ssa!, (Core.CodeInfo,CC.IRCode,CC.DomTree,Vector{CC.SlotInfo},Vector{Any}))
g["domsort_ssa!"] = @benchmarkable abs_call(CC.domsort_ssa!, (CC.IRCode,CC.DomTree))
g["quadratic"] = @benchmarkable abs_call(quadratic, (Int,))
g["method_match_cache"] = @benchmarkable abs_call(method_match_cache, (Float64,))
tune_benchmarks!(g)
end

Expand All @@ -210,6 +225,7 @@ let g = addgroup!(SUITE, "optimization")
g["construct_ssa!"] = @benchmarkable f() (setup = (f = opt_call(CC.construct_ssa!, (Core.CodeInfo,CC.IRCode,CC.DomTree,Vector{CC.SlotInfo},Vector{Any}))))
g["domsort_ssa!"] = @benchmarkable f() (setup = (f = opt_call(CC.domsort_ssa!, (CC.IRCode,CC.DomTree))))
g["quadratic"] = @benchmarkable f() (setup = (f = opt_call(quadratic, (Int,))))
g["method_match_cache"] = @benchmarkable f() (setup = (f = opt_call(method_match_cache, (Float64,))))
tune_benchmarks!(g)
end

Expand All @@ -226,6 +242,7 @@ let g = addgroup!(SUITE, "allinference")
g["construct_ssa!"] = @benchmarkable inf_call(CC.construct_ssa!, (Core.CodeInfo,CC.IRCode,CC.DomTree,Vector{CC.SlotInfo},Vector{Any}))
g["domsort_ssa!"] = @benchmarkable inf_call(CC.domsort_ssa!, (CC.IRCode,CC.DomTree))
g["quadratic"] = @benchmarkable inf_call(quadratic, (Int,))
g["method_match_cache"] = @benchmarkable inf_call(method_match_cache, (Float64,))
tune_benchmarks!(g)
end

Expand Down

0 comments on commit 1e8a1c4

Please sign in to comment.