Slow function call with float and None
I'm having issues with an unusually slow function call. Unfortunately, I can't make the example any smaller than this:
eq = lambda a, b: a == b
# SQL-style null handling
le = lambda a, b: a is not None and a <= b
def select(data, comparator, value):
return [d for d in data if comparator(d["field"], value)]
data = [{"field": 0.1}, {"field": None}] * 1000000
select(data, eq, None)
select(data, le, 0)
The first filtering operation here takes 0.1s - the second one 94s!
This showed up when I updated the le
function from the JS-like lambda a, b: (a or 0) <= b
to the SQL-like lambda a, b: a is not None and a <= b
. The former is still fast, the latter very slow (cpython speeds are around 0.2s).