From 2ae8a9424ec16c054f83e02895986c75dec576db Mon Sep 17 00:00:00 2001 From: Prabhat Sachdeva Date: Fri, 21 Nov 2025 17:22:11 +0530 Subject: [PATCH] Improve scalar UDFs performance --- singlestoredb/functions/ext/asgi.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/singlestoredb/functions/ext/asgi.py b/singlestoredb/functions/ext/asgi.py index d9090b38..3b2163c5 100755 --- a/singlestoredb/functions/ext/asgi.py +++ b/singlestoredb/functions/ext/asgi.py @@ -326,15 +326,16 @@ async def do_func( rows: Sequence[Sequence[Any]], ) -> Tuple[Sequence[int], List[Tuple[Any, ...]]]: '''Call function on given rows of data.''' - out = [] + tasks = [] async with timer('call_function'): for row in rows: cancel_on_event(cancel_event) if is_async: - out.append(await func(*row)) + tasks.append(func(*row)) else: - out.append(func(*row)) - return row_ids, list(zip(out)) + tasks.append(asyncio.to_thread(func, *row)) + + return row_ids, list(zip(await asyncio.gather(*tasks))) return do_func