Skip to content

Commit 26b0b6e

Browse files
authored
inference: remove CachedMethodTable (#44240)
Since we couldn't confirm any performance benefit from `CachedMethodTable` in the current infrastructure (see the benchmark results in #44240), now I'd like to propose to eliminate that entirely and save a bit of space.
1 parent aa2421d commit 26b0b6e

File tree

3 files changed

+16
-42
lines changed

3 files changed

+16
-42
lines changed

base/compiler/inferencestate.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ mutable struct InferenceState
6565
# The place to look up methods while working on this function.
6666
# In particular, we cache method lookup results for the same function to
6767
# fast path repeated queries.
68-
method_table::CachedMethodTable{InternalMethodTable}
68+
method_table::InternalMethodTable
6969

7070
# The interpreter that created this inference state. Not looked at by
7171
# NativeInterpreter. But other interpreters may use this to detect cycles
@@ -141,7 +141,7 @@ mutable struct InferenceState
141141
cache === :global, false, false,
142142
Effects(consistent, ALWAYS_TRUE, ALWAYS_TRUE, ALWAYS_TRUE,
143143
inbounds_taints_consistency),
144-
CachedMethodTable(method_table(interp)),
144+
method_table(interp),
145145
interp)
146146
result.result = frame
147147
cache !== :no && push!(get_inference_cache(interp), result)

base/compiler/methodtable.jl

+14-39
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,6 @@
22

33
abstract type MethodTableView; end
44

5-
struct MethodLookupResult
6-
# Really Vector{Core.MethodMatch}, but it's easier to represent this as
7-
# and work with Vector{Any} on the C side.
8-
matches::Vector{Any}
9-
valid_worlds::WorldRange
10-
ambig::Bool
11-
end
12-
length(result::MethodLookupResult) = length(result.matches)
13-
function iterate(result::MethodLookupResult, args...)
14-
r = iterate(result.matches, args...)
15-
r === nothing && return nothing
16-
match, state = r
17-
return (match::MethodMatch, state)
18-
end
19-
getindex(result::MethodLookupResult, idx::Int) = getindex(result.matches, idx)::MethodMatch
20-
215
"""
226
struct InternalMethodTable <: MethodTableView
237
@@ -39,19 +23,21 @@ struct OverlayMethodTable <: MethodTableView
3923
mt::Core.MethodTable
4024
end
4125

42-
"""
43-
struct CachedMethodTable <: MethodTableView
44-
45-
Overlays another method table view with an additional local fast path cache that
46-
can respond to repeated, identical queries faster than the original method table.
47-
"""
48-
struct CachedMethodTable{T} <: MethodTableView
49-
cache::IdDict{Any, Union{Missing, MethodLookupResult}}
50-
table::T
26+
struct MethodLookupResult
27+
# Really Vector{Core.MethodMatch}, but it's easier to represent this as
28+
# and work with Vector{Any} on the C side.
29+
matches::Vector{Any}
30+
valid_worlds::WorldRange
31+
ambig::Bool
32+
end
33+
length(result::MethodLookupResult) = length(result.matches)
34+
function iterate(result::MethodLookupResult, args...)
35+
r = iterate(result.matches, args...)
36+
r === nothing && return nothing
37+
match, state = r
38+
return (match::MethodMatch, state)
5139
end
52-
CachedMethodTable(table::T) where T =
53-
CachedMethodTable{T}(IdDict{Any, Union{Missing, MethodLookupResult}}(),
54-
table)
40+
getindex(result::MethodLookupResult, idx::Int) = getindex(result.matches, idx)::MethodMatch
5541

5642
"""
5743
findall(sig::Type, view::MethodTableView; limit=typemax(Int))
@@ -91,13 +77,6 @@ function findall(@nospecialize(sig::Type), table::OverlayMethodTable; limit::Int
9177
return MethodLookupResult(ms::Vector{Any}, WorldRange(_min_val[], _max_val[]), _ambig[] != 0)
9278
end
9379

94-
function findall(@nospecialize(sig::Type), table::CachedMethodTable; limit::Int=typemax(Int))
95-
box = Core.Box(sig)
96-
return get!(table.cache, sig) do
97-
findall(box.contents, table.table; limit=limit)
98-
end
99-
end
100-
10180
"""
10281
findsup(sig::Type, view::MethodTableView)::Union{Tuple{MethodMatch, WorldRange}, Nothing}
10382
@@ -121,10 +100,6 @@ function findsup(@nospecialize(sig::Type), table::InternalMethodTable)
121100
(result.method, WorldRange(min_valid[], max_valid[]))
122101
end
123102

124-
# This query is not cached
125-
findsup(@nospecialize(sig::Type), table::CachedMethodTable) = findsup(sig, table.table)
126-
127103
isoverlayed(::MethodTableView) = error("unsatisfied MethodTableView interface")
128104
isoverlayed(::InternalMethodTable) = false
129105
isoverlayed(::OverlayMethodTable) = true
130-
isoverlayed(mt::CachedMethodTable) = isoverlayed(mt.table)

base/compiler/types.jl

-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ struct NativeInterpreter <: AbstractInterpreter
263263
# incorrect, fail out loudly.
264264
@assert world <= get_world_counter()
265265

266-
267266
return new(
268267
# Initially empty cache
269268
Vector{InferenceResult}(),

0 commit comments

Comments
 (0)