Release of GIL
At present numpy release Global Interpreter Lock or GIL for all two or one operand loops. MacroNPY_BEGIN_THREADS is used to save the Python state and releases the GIL. Hence it can be placed right before code that does not need the Python interpreter. Like in ufunc_object.c trivial_three_operand_loop and trivial_two_operand_loop use it for innerloop.Not so good for small ones
But for short length array, it produces relative overhead instead. Releasing GIL for smaller operations doesn't benefit at all.Here, Nathaniel has mentioned few things as
- Vast majority of numpy code is single-threaded, so dropping the GIL is pure overhead.
- Dropping the GIL for microseconds at a time probably produces no benefit even for multi-threaded code, since by the time the other thread gets started and starts producing useful work, the numpy loop is done.
- Most numpy code calls
+a lot more than it callssinor even**or/.