Skip to content

Commit 8ea2899

Browse files
KDr2yebai
andauthored
Peformance Optimization (#138)
* use generated function to run instruction * optimize mem allocation * optiomize copy and update_var! * optimization on constant * remove MacroTools * don't optimize function call * opt const function-call conditionally * remove `val` * breakdown benchmarks * use Vector as bindings * use Int as box, inline _update_var! manually * code refactor * remove unused code * Update src/tapedfunction.jl * add comments * update comments * update from review * update from review * use a compact bindings, remove the offset limitation * bugfix: unify TypedSlot and SlotNumber * document * refine types * give bindings a sizehint * update docs for `tape_copy` * remove outdated comments * update from review * disable logging by default * update comments * use vector to store arg indices * rename fields in TF * remove TempBindings * Update tapedfunction.jl * Update Project.toml Co-authored-by: Hong Ge <[email protected]>
1 parent 24b3d4b commit 8ea2899

File tree

4 files changed

+224
-134
lines changed

4 files changed

+224
-134
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"
33
license = "MIT"
44
desc = "Tape based task copying in Turing"
55
repo = "https://github.com/TuringLang/Libtask.jl.git"
6-
version = "0.7.3"
6+
version = "0.7.4"
77

88
[deps]
99
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"

perf/benchmark.jl

+20-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function benchmark_driver!(f, x...; f_displayname=string(f))
88
x = (x..., nothing)
99

1010
println("benchmarking $(f_displayname)...")
11-
tf = Libtask.TapedFunction(f, x...);
11+
tf = Libtask.TapedFunction(f, x...)
1212

1313
print(" Run Original Function:")
1414
@btime $f($(x)...)
@@ -24,18 +24,18 @@ function benchmark_driver!(f, x...; f_displayname=string(f))
2424
GC.gc()
2525

2626
print(" Run TapedTask: ")
27-
x = (x[1:end-1]..., produce);
27+
x = (x[1:end-1]..., produce)
2828
# show the number of produce calls inside `f`
29-
f_task = (f, x; verbose=false) -> begin
30-
tt = TapedTask(f, x...);
29+
function f_task(f, x; verbose=false)
30+
tt = TapedTask(f, x...)
3131
c = 0
3232
while consume(tt)!==nothing
3333
c+=1
3434
end
35-
verbose && print("#produce=", c, "; ");
35+
verbose && print("#produce=", c, "; ")
3636
end
37-
# Note that we need to pass `f` instead of `tf` to avoid
38-
# default continuation in `TapedTask` constructor, see, e.g.
37+
# Note that we need to pass `f` instead of `tf` to avoid
38+
# default continuation in `TapedTask` constructor, see, e.g.
3939
# https://github.com/TuringLang/Libtask.jl/pull/135
4040
f_task(f, x; verbose=true) # print #produce calls
4141
@btime $f_task($f, $x)
@@ -109,4 +109,17 @@ benchmark_driver!(neural_net, xs...)
109109

110110
####################################################################
111111

112+
println("======= breakdown benchmark =======")
113+
114+
x = rand(100000)
115+
tf = Libtask.TapedFunction(ackley, x, nothing)
116+
tf(x, nothing);
117+
ins = tf.tape[45]
118+
b = ins.input[1]
119+
120+
@show ins.input |> length
121+
@btime map(x -> Libtask._lookup(tf, x), ins.input)
122+
@btime Libtask._lookup(tf, b)
123+
@btime tf.binding_values[b]
124+
112125
println("done")

0 commit comments

Comments
 (0)