Slowdown when omitting optional keyword arguments

I am finding that function call cost increases significantly when omitting an optional keywrd argument in a function. For example, consider

foo = jit(lambda a, b=2: a + b)

If this is called without passing the kwarg, i.e. foo(1), it takes ~10 microseconds on my machine. If the kwarg is passed, i.e. foo(1, b=2) the time goes to 70 nanoseconds. Interestingly calling foo(1, 2) further reduces the cost to ~50 nanoseconds, but that’s beside my original point.

Setting default arguments is very useful and this is prohibiting me from exposing efficient routines directly to Python code. Any suggestions?

I have just noticed that a response to a recent thread addresses this in a PR: Fixes poor performance when omitting default args in JIT-compiled fun… by jrenaud90 · Pull Request #10447 · numba/numba · GitHub

I will leave this here for completeness.