You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an argument to a Cython function is declared as not None, this adds a check early on that the argument is not None. However, in almost all cases, that check is performed again implicitly when it is converted to our desired type later in the function. Since they are far apart, the branch predictor or compiler generally doesn't optimize this out, and it's just unnecessary extra work. For a concrete example:
This inserts a check that it isn't None shortly after unpacking the arguments:
if (unlikely(((PyObject*)__pyx_v_tensorDataType) ==Py_None)) {
PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "tensorDataType"); __PYX_ERR(0, 44522, __pyx_L1_error)
}
However, this "None check" is implied when converting the value to an int because None is not convertible to an int.
We can remove these annotations without any change in safety or accepted types. The downside is that the error message may not be as nice or mention the name of the argument. If we put a try/except around the integer conversion, we may be able to have 100% equivalent behavior, but the performance implications of that would need to be measured.
Activity
mdboom commentedon Apr 28, 2026
This would be best done after the cython-gen/cybind merge.
mdboom commentedon Jun 23, 2026
Moving to P2 -- there's not much evidence this would have a major impact, so it's just "nice to have".