Skip to content

Conversation

@evnchn
Copy link
Collaborator

@evnchn evnchn commented Nov 27, 2025

Motivation

The gist of pipeline parallelization is that, should a task involve several steps which could have been in parallel but must be completed serially for each task, we want to break them down so that the parallelization takes place.

  • There are multiple steps for rendering a NiceGUI page: Page function execution, network transmission
  • But the page function is monolithic and the respinse is also monolithic 😞

This PR challenges the status quo.

Implementation

Even if nothing is done, there is already speedup, because the template is broken into 2, and now we have 3 parts:

  • Before elements string
  • elements string
  • After elements string

On top, this code is now possible:

@ui.page('/')
async def main():
    for _1 in range(5):
        for _2 in range(10000):
            ui.label('1')
        await asyncio.sleep(0.1)
        yield

Here, we have 5 chunks of 10000 elements, each generated 0.1 second apart.

Fast 4G

Before this PR: 2.38s
After this PR: 1.73s

Progress

  • I chose a meaningful title that completes the sentence: "If applied, this PR will..."
  • The implementation is complete. (I'm not sure)
  • Pytests are very necessary and pending.
  • Documentation is necessary and pending.
  • While the math checks out, we should do more testing to see if the time savings are worth it in real life. (2.38 vs 1.73)
  • Do we need explicit stream=True or can we infer?
  • How does this compare to just await client.connected() then push content changes through the outbox?
    • Push via outbox will lead to rendering and is slow that way.

@evnchn evnchn marked this pull request as draft November 27, 2025 06:23
@evnchn

This comment was marked as resolved.

@evnchn evnchn changed the title stream=True for page to use StreamingResponse Streamable pages with yield Nov 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant