Skip to content

Commit 2ae8a94

Browse files
committed
Improve scalar UDFs performance
1 parent 4adf1c5 commit 2ae8a94

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

singlestoredb/functions/ext/asgi.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,16 @@ async def do_func(
326326
rows: Sequence[Sequence[Any]],
327327
) -> Tuple[Sequence[int], List[Tuple[Any, ...]]]:
328328
'''Call function on given rows of data.'''
329-
out = []
329+
tasks = []
330330
async with timer('call_function'):
331331
for row in rows:
332332
cancel_on_event(cancel_event)
333333
if is_async:
334-
out.append(await func(*row))
334+
tasks.append(func(*row))
335335
else:
336-
out.append(func(*row))
337-
return row_ids, list(zip(out))
336+
tasks.append(asyncio.to_thread(func, *row))
337+
338+
return row_ids, list(zip(await asyncio.gather(*tasks)))
338339

339340
return do_func
340341

0 commit comments

Comments
 (0)