Some questions about Numba behavior

Hi,
I’m new to Numba and started with some simple operations.

I have some questions about Numba compile process and caching:

  1. I discover that when calling first time to a jit function, Numba takes more time to compile it.
    I guess that in that time Numba load it self to the memory or something alike.
    I think that a loading numba function, is not exists, but isnt it worth building one ?

  2. Any successive call to jitted function will be really quick.
    I think its not because of caching, but rather Numba stores the compiled function somewhere…
    Can anyone shed some light on what is Numba behavior ?
    Does Numba keep the compiled code ? where and for how long ?

  3. Modified

P.S
This is really a great tool, Thanks !

  1. Perhaps cache=True is what you’re looking for? Compiling Python code with @jit — Numba 0.55.0.dev0+438.g3131959c9.dirty-py3.7-linux-x86_64.egg documentation
  2. Numba does store the compiled function - it stores a separate version for each set of argument types, and if the function is called with a set of argument types that has already been compiled before, it will use the compiled version from the cache. These cached versions exist in a Dispatcher object, which is what is obtained when you decorate a function with @jit. The compiled versions last for the lifetime of the dispatcher - as long as it is in scope somewhere, the compiled versions exist. When it goes out of scope everywhere (e.g. if a new function with the same name is defined) then the compiled versions will cease to exist.
1 Like