Yes, it’s pretty slow and I’m not exactly sure what’s going on. Here’s an interesting example of something that’s wrong and causing a performance problem:
using BootlegCassette
using BootlegCassette: @context, overdub
@context Ctx
let x = Ref(1), y = Ref(2)
@btime overdub(Ctx(), *, $x[], $y[])
end;
#+RESULTS:
16.292 ns (0 allocations: 0 bytes)
Investigating the typed code doesn’t reveal anything amis:
@code_typed overdub(Ctx(), *, 1, 2)
#+RESULTS:
CodeInfo(
1 ─ %1 = Base.getfield(args, 3)::Int64
│ %2 = Base.getfield(args, 4)::Int64
│ %3 = (Core.Intrinsics.mul_int)(%1, %2)::Int64
└── return %3
) => Int64
but the LLVM code tells a different story:
@code_llvm overdub(Ctx(), *, 1, 2)
#+RESULTS:
; @ /home/mason/.julia/packages/IRTools/aSVI5/src/reflection/dynamo.jl:114 within `overdub'
define nonnull {}* @japi3_overdub_1970({}* %0, {}** %1, i32 %2, {}** %3) #0 {
top:
%4 = alloca {}**, align 8
store volatile {}** %1, {}*** %4, align 8
%5 = icmp ugt i32 %2, 2
br i1 %5, label %pass, label %fail
fail: ; preds = %top
%6 = sext i32 %2 to i64
call void @jl_bounds_error_tuple_int({}** %1, i64 %6, i64 3)
unreachable
pass: ; preds = %top
%.not = icmp eq i32 %2, 3
br i1 %.not, label %fail1, label %pass2
fail1: ; preds = %pass
call void @jl_bounds_error_tuple_int({}** %1, i64 3, i64 4)
unreachable
pass2: ; preds = %pass
%7 = getelementptr inbounds {}*, {}** %1, i64 2
%8 = bitcast {}** %7 to i64**
%9 = load i64*, i64** %8, align 8
%10 = getelementptr inbounds {}*, {}** %1, i64 3
%11 = bitcast {}** %10 to i64**
%12 = load i64*, i64** %11, align 8
; @ /home/mason/.julia/packages/IRTools/aSVI5/src/reflection/dynamo.jl within `overdub' @ int.jl:88
; ┌ @ /home/mason/Dropbox/Julia/BootlegCassette/src/BootlegCassette.jl:49 within `overdub_pass'
; │┌ @ /home/mason/Dropbox/Julia/BootlegCassette/src/BootlegCassette.jl:55 within `overdub'
%13 = load i64, i64* %9, align 8
%14 = load i64, i64* %12, align 8
%15 = mul i64 %14, %13
%16 = call nonnull {}* @jl_box_int64(i64 signext %15)
ret {}* %16
; └└
}
Somehow, LLVM doesn’t seem to know how many arguments there are to the function or something.