> ## Documentation Index
> Fetch the complete documentation index at: https://nixtlaverse.nixtla.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Numba caching

> Enabling caching for numba functions to reduce cold-starts

`statsforecast` makes heavy use of [numba](https://numba.pydata.org/) to
speed up several critical functions that estimate model parameters. This
comes at a cost though, which is that the functions have to be [JIT
compiled](https://en.wikipedia.org/wiki/Just-in-time_compilation) the
first time they’re run, which can be expensive. Once a function has been
JIT compiled, subsequent calls are significantly faster. One problem is
that this compilation is saved (by default) on a per-session basis.

In order to mitigate the compilation overhead numba offers the option to
cache the function compiled code to a file, which can be then reused
across sessions, and even copied over to different machines that share
the same CPU characteristics ([more
info](https://numba.pydata.org/numba-doc/latest/developer/caching.html#cache-sharing)).

To leverage caching, you can set the `NIXTLA_NUMBA_CACHE` environment
variable (e.g. `NIXTLA_NUMBA_CACHE=1`), which will enable caching for
all functions. By default the cache is saved to the `__pycache__`
directory, but you can override this with the `NUMBA_CACHE_DIR`
environment variable to save it to a different path
(e.g. `NUMBA_CACHE_DIR=numba_cache`), you can find more information in
the
[docs](https://numba.pydata.org/numba-doc/latest/reference/envvars.html#envvar-NUMBA_CACHE_DIR).

If you want to have this enabled for all your sessions, we suggest
adding `export NIXTLA_NUMBA_CACHE=1` to your profile files, such as
`.bashrc`, `.zshrc`, etc.
