Numba caching
Enabling caching for numba functions to reduce cold-starts
statsforecast
makes heavy use of numba 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 the
first time they’re run, which can be expensive. Once a function has ben
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).
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.
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.