# \`findlast()\` with predicate: allocations depending on argument types

**URL:** <https://discourse.julialang.org/t/findlast-with-predicate-allocations-depending-on-argument-types/72246>\
**Category:** General Usage\
**Created:** [November 29, 2021, 4:27pm UTC](https://discourse.julialang.org/t/findlast-with-predicate-allocations-depending-on-argument-types/72246 "2021-11-29T16:27:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [November 29, 2021, 4:27pm UTC](https://discourse.julialang.org/t/findlast-with-predicate-allocations-depending-on-argument-types/72246/1 "2021-11-29T16:27:06Z")

</div>

When I run `findlast(y -> y≤x, xrange)`, the number of allocations changes depending on the sameness of the type of `x` and the element type of `xrange`. Here is an example:

```julia-repl
julia> VERSION
v"1.6.5-pre.0"

julia> using BenchmarkTools

julia> xi = 1; # Int64

julia> xf = 0.5; # Float64

julia> xrange = 1:100; # Int64 range

julia> @btime findlast(y -> y≤$xi, $xrange);
  165.173 ns (0 allocations: 0 bytes) # no allocations for typeof(xi) == eltype(xrange)

julia> @btime findlast(y -> y≤$xf, $xrange);
  270.025 ns (2 allocations: 48 bytes) # allocations for typeof(xi) ≠ eltype(xrange)

```

What is the explanation of this difference? I compared `@code_llvm` and `@code_native` of the two executions `findlast(y -> y≤xi, xrange)` and `findlast(y -> y≤xf, xrange)`, but I was not able to identify the lines causing allocations in the latter.
