On Mon, May 18, 2015 at 8:54 AM, Scott Jones <
scott.pa...@gmail.com> wrote:
> I may have to update the section of the documentation I added, about
> Noteworthy differences... this one worked, but causes an unexpected
> performance penalty...
> (A C/C++ programmer would normally think of using an unsigned value,
> precisely to improve performance... where here it seems to be the opposite,
> because of the boxing going on...)
I think the compiler is smart enough to omit those boxing. Have you
checked code_llvm and see there's really boxing going on? (following
is my simple test)
P.S. personally what I usually do to figure out whether there's any
allocation going on is simply running @code_llvm and look for gc frame
and alloc* function calls :P
```julia
julia> function f(str)
l::UInt = sizeof(str)
return l + 1
end
f (generic function with 1 method)
julia> @code_llvm f(Int8[])
define i64 @julia_f_44546(%jl_value_t*) {
top:
%1 = call i64 @julia_sizeof1541(%jl_value_t* %0)
%2 = icmp sgt i64 %1, -1
br i1 %2, label %pass, label %fail
fail: ; preds = %top
%3 = load %jl_value_t** @jl_inexact_exception, align 8
call void @jl_throw_with_superfluous_argument(%jl_value_t* %3, i32 2)
unreachable
pass: ; preds = %top
%4 = add i64 %1, 1
ret i64 %4
}
julia> @code_typed f(Int8[])
1-element Array{Any,1}:
:($(Expr(:lambda, Any[:str],
Any[Any[:l],Any[Any[:str,Array{Int8,1},0],Any[:l,UIn
t64,18]],Any[],Any[Int64]], :(begin # none, line 2:
GenSym(0) = sizeof(str::Array{Int8,1})::Int64
l = (top(box))(UInt64,(top(check_top_bit))(GenSym(0))) # line 3:
return (top(box))(UInt64,(top(add_int))(l::UInt64,(top(box))(UInt64,(top(c
heck_top_bit))(1))))
end::UInt64))))
```