# Dispatch on Value allocating

**URL:** <https://discourse.julialang.org/t/dispatch-on-value-allocating/26337>\
**Category:** Performance\
**Tags:** question\
**Created:** [July 14, 2019, 10:43am UTC](https://discourse.julialang.org/t/dispatch-on-value-allocating/26337 "2019-07-14T10:43:12Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 14, 2019, 6:48pm UTC](https://discourse.julialang.org/t/dispatch-on-value-allocating/26337/9 "2019-07-14T18:48:03Z")

</div>

> [@cshenton](#):
>
> Is a dispatch on a `Val(foo)` where foo is a compile time constant generally not compiled away?

Yes, it generally will.

```julia
julia> f() = ntuple(x -> x + 5, Val(2))
f (generic function with 2 methods)

julia> @code_llvm f()

; @ REPL[45]:1 within `f'
define void @julia_f_12684([2 x i64]* noalias nocapture sret) {
top:
  %1 = bitcast [2 x i64]* %0 to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %1, i8* bitcast ([2 x i64]* @0 to i8*), i64 16, i32 8, i1 false)
  ret void
}

julia> @code_native f()
        .section __TEXT,__ text,regular,pure_instructions
; ┌ @ REPL[49]:1 within `f'
        decl %eax
        movl $429409128, %eax ## imm = 0x19984368
        addl %eax, (%eax)
        addb %al, (%eax)
        vmovups (%eax), %xmm0
        vmovups %xmm0, (%edi)
        decl %eax
        movl %edi, %eax
        retl
        nopw %cs:(%eax,%eax)
; └

```

---

_[View the full topic](https://discourse.julialang.org/t/dispatch-on-value-allocating/26337)._
