Skip to content

Commit 19d888b

Browse files
authored
go back to using a Vector for recycled frames (#245)
1 parent 56f4222 commit 19d888b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/construct.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ rather than recursed into via the interpreter.
2626
"""
2727
const compiled_modules = Set{Module}()
2828

29-
const junk = Base.IdSet{FrameData}() # to allow re-use of allocated memory (this is otherwise a bottleneck)
30-
recycle(frame) = push!(junk, frame.framedata) # using an IdSet ensures that a frame can't be added twice
29+
const junk = FrameData[] # to allow re-use of allocated memory (this is otherwise a bottleneck)
30+
const debug_recycle = Base.RefValue(false)
31+
@noinline _check_frame_not_in_junk(frame) = @assert frame.framedata junk
32+
@inline function recycle(frame)
33+
debug_recycle[] && _check_frame_not_in_junk(frame)
34+
push!(junk, frame.framedata)
35+
end
3136

3237
const empty_svec = Core.svec()
3338

@@ -245,9 +250,8 @@ function prepare_framedata(framecode, argvals::Vector{Any}, caller_will_catch_er
245250
ssavt = src.ssavaluetypes
246251
ng = isa(ssavt, Int) ? ssavt : length(ssavt::Vector{Any})
247252
nargs, meth_nargs = length(argvals), Int(meth.nargs)
248-
if !isempty(junk)
249-
olddata = first(junk)
250-
delete!(junk, olddata)
253+
if length(junk) > 0
254+
olddata = pop!(junk)
251255
locals, ssavalues, sparams = olddata.locals, olddata.ssavalues, olddata.sparams
252256
exception_frames, last_reference = olddata.exception_frames, olddata.last_reference
253257
last_exception = olddata.last_exception
@@ -523,6 +527,7 @@ T = Float64
523527
See [`enter_call`](@ref) for a similar approach not based on expressions.
524528
"""
525529
function enter_call_expr(expr; enter_generated = false)
530+
empty!(junk)
526531
r = determine_method_for_expr(expr; enter_generated = enter_generated)
527532
if isa(r, Tuple)
528533
return prepare_frame(r[1:end-1]...)
@@ -564,6 +569,7 @@ would be created by the generator.
564569
See [`enter_call_expr`](@ref) for a similar approach based on expressions.
565570
"""
566571
function enter_call(@nospecialize(finfo), @nospecialize(args...); kwargs...)
572+
empty!(junk)
567573
if isa(finfo, Tuple)
568574
f = finfo[1]
569575
enter_generated = finfo[2]::Bool

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ if !isdefined(@__MODULE__, :read_and_parse)
77
include("utils.jl")
88
end
99

10+
JuliaInterpreter.debug_recycle[] = true
11+
1012
@testset "Main tests" begin
1113
include("interpret.jl")
1214
include("toplevel.jl")

0 commit comments

Comments
 (0)