# Type Instability in performance critical function

**URL:** https://discourse.julialang.org/t/type-instability-in-performance-critical-function/57195
**Category:** Performance
**Created:** [March 15, 2021, 1:39pm UTC](https://discourse.julialang.org/t/type-instability-in-performance-critical-function/57195 "2021-03-15T13:39:23Z")
**Posts on this page:** 1
**Showing post:** 17

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [March 15, 2021, 4:00pm UTC](https://discourse.julialang.org/t/type-instability-in-performance-critical-function/57195/17 "2021-03-15T16:00:24Z")

</div>

> [@lmiq](#):
>
> ```julia
> function my_indexin(x,y)
> indxs = Int[]
> for (i, xval) in pairs(x)
> for (j, yval) in pairs(y)
> if yval == xval
> push!(indxs,j)
> break
> end
> end
> end
> indxs
> end
> 
> ```

It was there, hidden in the “\> Code”. Please check if it is correct. I think it is.

One note: for small array sizes this function is faster than the builtin `indexin`. But it is slower for larger arrays. Also the builtin returns `nothing` for elements not found, while this one simply does not push the element into the array.

---

_[View the full topic](https://discourse.julialang.org/t/type-instability-in-performance-critical-function/57195)._
