Skip to content

Commit

Permalink
Encapsulate ccalls to enhance interpreter usage (#43)
Browse files Browse the repository at this point in the history
If Julia compiles the returned expression, we will "miss" the inference 
time because the compilation happens before we turn snooping on.

The logic in 
https://github.com/JuliaLang/julia/blob/84e839227f7762b6dfa0821247cd132cf15e3581/src/toplevel.c#L793-L815
indicates that the `ccall`s could force Julia to use the compiler,
so move these inside a function.
  • Loading branch information
timholy committed Dec 3, 2019
1 parent 677ac97 commit 9cd43de
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/SnoopCompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ if VERSION >= v"1.2.0-DEV.573"
return ret
end

@noinline start_timing() = ccall(:jl_set_typeinf_func, Cvoid, (Any,), typeinf_ext_timed)
@noinline stop_timing() = ccall(:jl_set_typeinf_func, Cvoid, (Any,), Core.Compiler.typeinf_ext)

function sort_timed_inf(tmin)
data = __inf_timing__
if tmin > 0
Expand All @@ -47,12 +50,12 @@ if VERSION >= v"1.2.0-DEV.573"
error("at most two arguments are supported")
end
quote
empty!($__inf_timing__)
ccall(:jl_set_typeinf_func, Cvoid, (Any,), $typeinf_ext_timed)
empty!(__inf_timing__)
start_timing()
try
$(esc(cmd))
finally
ccall(:jl_set_typeinf_func, Cvoid, (Any,), Core.Compiler.typeinf_ext)
stop_timing()
end
$sort_timed_inf($tmin)
end
Expand Down Expand Up @@ -396,6 +399,8 @@ if VERSION >= v"1.2.0-DEV.573"
# (the *.ji file stores only the inferred code)
precompile(typeinf_ext_timed, (Core.MethodInstance, Core.Compiler.Params))
precompile(typeinf_ext_timed, (Core.MethodInstance, UInt))
precompile(start_timing, ())
precompile(stop_timing, ())
nothing
end
end
Expand Down

0 comments on commit 9cd43de

Please sign in to comment.