Skip to content

Large number of bindings will block the main loop #2290

Closed
@rodja

Description

Description

When using a large number of bindings the main loop is blocked significantly. Naturally the actual number depends on the used CPU. On my Apple Silicon M3 MAX the following code blocks the main thread for more than 1 second:

from nicegui import ui

data = {'msg': 'x'}

@ui.page('/')
def index():
    with ui.row().classes('gap-0'):
        for _ in range(100):
            with ui.column().classes('gap-0'):
                for _ in range(10):
                    ui.label().bind_text_from(data, 'msg')

def show_asyncio_debug_infos():
    loop = asyncio.get_running_loop()
    loop.set_debug(True)
    loop.slow_callback_duration = 0.05

app.on_startup(show_asyncio_debug_infos)

ui.run(reconnect_timeout=0)

Which outputs

NiceGUI ready to go on http://localhost:3494, and http://192.168.1.207:3494
WARNING:asyncio:Executing <Task finished name='unnamed task' coro=<page.__call__.<locals>.decorated.<locals>.wait_for_result() done, defined at /Users/rodja/Projects/nicegui/nicegui/page.py:104> result=None created at /Users/rodja/Projects/nicegui/nicegui/background_tasks.py:23> took 0.374 seconds
WARNING:asyncio:Executing <Task finished name='unnamed task' coro=<page.__call__.<locals>.decorated.<locals>.wait_for_result() done, defined at /Users/rodja/Projects/nicegui/nicegui/page.py:104> result=None created at /Users/rodja/Projects/nicegui/nicegui/background_tasks.py:23> took 1.124 seconds

And after some delay also

WARNING:nicegui:binding propagation for 2000 active links took 0.010 s
WARNING:nicegui:binding propagation for 2000 active links took 0.010 s
WARNING:nicegui:binding propagation for 2000 active links took 0.010 s
WARNING:nicegui:binding propagation for 2000 active links took 0.010 s
WARNING:nicegui:binding propagation for 2000 active links took 0.013 s
WARNING:nicegui:binding propagation for 2000 active links took 0.010 s

And when closing the page:

WARNING:asyncio:Executing <Task finished name='unnamed task' coro=<Client.handle_disconnect.<locals>.handle_disconnect() done, defined at /Users/rodja/Projects/nicegui/nicegui/client.py:243> result=None created at /Users/rodja/Projects/nicegui/nicegui/background_tasks.py:23> took 0.071 seconds

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions