# Why numba decorator cause 10 times slower run

**URL:** <https://numba.discourse.group/t/why-numba-decorator-cause-10-times-slower-run/1539>\
**Category:** Support: How do I do ...?\
**Created:** [August 30, 2022, 10:51am UTC](https://numba.discourse.group/t/why-numba-decorator-cause-10-times-slower-run/1539 "2022-08-30T10:51:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ali\_Sh](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Ali\_Sh](https://numba.discourse.group/u/Ali_Sh)\
**Post date:** [August 30, 2022, 10:52am UTC](https://numba.discourse.group/t/why-numba-decorator-cause-10-times-slower-run/1539/1 "2022-08-30T10:52:00Z")

</div>

I don’t know why `nb.njit` have adverse effect on the performance of my code:

```auto
lst = [np.array([[1, 2],
                 [3, 4]]),
       np.array([[1, 2, 3],
                 [4, 5, 6]]),
       np.array([[1, 2],
                 [3, 4],
                 [5, 6]])]

lst = lst * 10000

def new_(lst):
    maxx = 0
    maxy = 0
    for x in lst:
       maxx = max(x.shape[0], maxx)
       maxy = max(x.shape[1], maxy)

    arr = np.zeros((len(lst), maxx, maxy))
    for i in range(len(lst)):
        arr[i, :lst[i].shape[0], :lst[i].shape[1]] = lst[i]
    return arr

@nb.njit(nb.float64[:, :, ::1](nb.types.List(nb.int_[:, ::1], reflected=True)))
def numba_s2(lst):
    maxx = 0
    maxy = 0
    for x in lst:
        maxx = max(x.shape[0], maxx)
        maxy = max(x.shape[1], maxy)

    arr = np.zeros((len(lst), maxx, maxy))
    for i in range(len(lst)):
        arr[i, :lst[i].shape[0], :lst[i].shape[1]] = lst[i]
    return arr

```

It shows a warning too on both my machine and gloogle colab:

```auto
/usr/local/lib/python3.7/dist-packages/numba/core/ir_utils.py:2147: NumbaPendingDeprecationWarning: 
Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'lst' of function 'numba_s2'.

For more information visit https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types

File "<ipython-input-2-22beb8072bc3>", line 33:
@nb.njit(nb.float64[:, :, ::1](nb.types.List(nb.int_[:, ::1], reflected=True)))
def numba_s2(lst):
^

  warnings.warn(NumbaPendingDeprecationWarning(msg, loc=loc))

```

**Is it related to this warning??**

**Can numba be applied efficiently on this code to get better performances?**

_ **my machine:** _

- python 3.10
- numpy 1.22.3
- numba 0.55.2

---

<div class="post-metadata">

**Author:** ![luk-f-a](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/luk-f-a/32/56_2.png) [@luk-f-a](https://numba.discourse.group/u/luk-f-a)\
**Post date:** [August 30, 2022, 5:32pm UTC](https://numba.discourse.group/t/why-numba-decorator-cause-10-times-slower-run/1539/2 "2022-08-30T17:32:43Z")

</div>

hi @Ali_Sh how are you measuring the time? Are you including the compilation time in the comparison?

---

<div class="post-metadata">

**Author:** ![Ali\_Sh](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Ali\_Sh](https://numba.discourse.group/u/Ali_Sh)\
**Post date:** [August 30, 2022, 5:59pm UTC](https://numba.discourse.group/t/why-numba-decorator-cause-10-times-slower-run/1539/3 "2022-08-30T17:59:12Z")

</div>

@luk-f-a I have used %timeit (`%timeit -n10 numba_s2(lst)`) on Colab. Did you check the performance and it is reasonable in your test?

---

<div class="post-metadata">

**Author:** ![Rutger](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/rutger/32/446_2.png) [@Rutger](https://numba.discourse.group/u/Rutger)\
**Post date:** [August 31, 2022, 6:53am UTC](https://numba.discourse.group/t/why-numba-decorator-cause-10-times-slower-run/1539/4 "2022-08-31T06:53:43Z")

</div>

The warning you’re seeing is definitely a clue. You’re better off using a typed List.

You can create a Numba typed List from an existing Python list using:

```python
lst_nb = nb.typed.List(lst)

```

You can then drop the `reflected=True`, and I also think you should use `nb.types.ListType` in the signature.

```python
@nb.njit(nb.float64[:, :, :](nb.types.ListType(nb.int_[:, ::1])))
def numba_s2(lst):
    maxx = 0
    maxy = 0
    for x in lst:
        maxx = max(x.shape[0], maxx)
        maxy = max(x.shape[1], maxy)

    arr = np.zeros((len(lst), maxx, maxy))
    for i in range(len(lst)):
        arr[i, :lst[i].shape[0], :lst[i].shape[1]] = lst[i]
    return arr

numba_s2(lst_nb)

```

For me that makes this function about 15x faster compared to the pure Python one, using the same size input as in your OP.
