Performance regression in 1D array indexing
Author: cliffckerrCreated Sep 22, 2026Updated Sep 28, 2026
Labelsperformancebug - regression
In Numba v0.65 and earlier, indexing a large (>5000 element) array was faster in a jitted function than in plain NumPy. However, starting in v0.66, it became roughly 1.5-2.0x slower, depending on the size of the array (and slower than NumPy in all cases). The explicitly written loop is still fast.
Script to reproduce:
from time import perf_counter
import numpy as np
import numba as nb
def np_read(arr, inds):
return arr[inds]
def np_write(arr, inds, vals):
arr[inds] = vals
@nb.jit
def nb_read(arr, inds):
return arr[inds]
@nb.jit
def nb_write(arr, inds, vals):
arr[inds] = vals
@nb.jit
def nl_read(arr, inds):
out = np.empty(len(inds), dtype=arr.dtype)
for i, ind in enumerate(inds):
out[i] = arr[ind]
return out
@nb.jit
def nl_write(arr, inds, vals):
for i, ind in enumerate(inds):
arr[ind] = vals[i]
seed = 0
array_size = 200_000
n_inds = 100_000
rng = np.random.default_rng(seed)
arr = rng.random(array_size)
inds = rng.integers(0, array_size, n_inds)
vals = rng.random(n_inds)
def benchmark(fn, *args):
timings = []
for _ in range(100):
t0 = perf_counter()
fn(*args)
t1 = perf_counter()
timings.append(t1 - t0)
min_time = min(timings)*1e6
return f'{min_time:0.0f} μs'
np_read_time = benchmark(np_read, arr, inds)
nb_read_time = benchmark(nb_read, arr, inds)
nl_read_time = benchmark(nl_read, arr, inds)
np_write_time = benchmark(np_write, arr, inds, vals)
nb_write_time = benchmark(nb_write, arr, inds, vals)
nl_write_time = benchmark(nl_write, arr, inds, vals)
print(f"numba {nb.__version__}")
print(f" numpy arr[inds] {np_read_time}")
print(f" njit arr[inds] {nb_read_time}")
print(f" nbloop arr[inds] {nl_read_time}")
print()
print(f" numpy arr[inds]=vals {np_write_time}")
print(f" njit arr[inds]=vals {nb_write_time}")
print(f" nbloop arr[inds]=vals {nl_write_time}")Output:
# numba 0.65.1
numpy arr[inds] 104 μs
njit arr[inds] 80 μs # <- 23% faster than numpy
nbloop arr[inds] 80 μs
numpy arr[inds]=vals 187 μs
njit arr[inds]=vals 153 μs # <- 18% faster than numpy
nbloop arr[inds]=vals 152 μs
# numba 0.67.0
numpy arr[inds] 104 μs
njit arr[inds] 131 μs # <- 1.64x slower than v0.65
nbloop arr[inds] 82 μs
numpy arr[inds]=vals 188 μs
njit arr[inds]=vals 256 μs # <- 1.67x slower than v0.65
nbloop arr[inds]=vals 154 μsThe regression was discovered running performance tests for Starsim, and was caused by adding support for multidimensional indexing in v0.66. Specifically, it seems like https://github.com/numba/numba/pull/10567, which was the fix for https://github.com/numba/numba/issues/10643 (an 8x performance regression for small arrays), introduced this 2x performance regression for larger arrays.
Source: numba/numba