# Extra allocation with \`T::DataType\`?

**URL:** <https://discourse.julialang.org/t/extra-allocation-with-t-datatype/85930>\
**Category:** Performance\
**Created:** [August 18, 2022, 2:45pm UTC](https://discourse.julialang.org/t/extra-allocation-with-t-datatype/85930 "2022-08-18T14:45:12Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [August 19, 2022, 12:36am UTC](https://discourse.julialang.org/t/extra-allocation-with-t-datatype/85930/16 "2022-08-19T00:36:14Z")

</div>

The native code is short and looks identical. I can’t read assembly but whenever there’s type instability or extra allocations I expect way more lines. Last week I also ran into another example where 2 versions of a method had the [same `@code_native` but different `@btime`](https://discourse.julialang.org/t/recursive-inner-functions-a-thousand-times-slower/85604/3). I’m on a Mac so anyone with a different machine should corroborate.

```julia
julia> foo(T,x) = exp(T(x))
foo (generic function with 1 method)

julia> foo(x) = exp(Float64(x))
foo (generic function with 2 methods)

julia> @code_native foo(Float64,10)
	.section	__TEXT,__ text,regular,pure_instructions
; ┌ @ REPL[1]:1 within `foo`
	subq	$8, %rsp
; │┌ @ float.jl:146 within `Float64`
	vcvtsi2sd	%rdi, %xmm0, %xmm0
; │└
	movabsq	$exp, %rax
	callq	*%rax
	popq	%rax
	retq
	nopw	(%rax,%rax)
; └

julia> @code_native foo(10)
	.section	__TEXT,__ text,regular,pure_instructions
; ┌ @ REPL[2]:1 within `foo`
	subq	$8, %rsp
; │┌ @ float.jl:146 within `Float64`
	vcvtsi2sd	%rdi, %xmm0, %xmm0
; │└
	movabsq	$exp, %rax
	callq	*%rax
	popq	%rax
	retq
	nopw	(%rax,%rax)
; └

```

---

_[View the full topic](https://discourse.julialang.org/t/extra-allocation-with-t-datatype/85930)._
