You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support deferring/streaming render output instead of producing the whole HTML string synchronously.
Why:django-components#1337. Large pages could start emitting before the whole tree finishes rendering.
Current state: the pipeline is eager. Rendering is already deferred and depth-unbounded (stack-driven), but there is no streaming/lazy part type: RenderPart = str | CitryRender | DeferredComponent | Placeholder (packages/py/citry/citry/citry_render.py).
Findings from the September 2026 performance experiments
Streaming is worth exploring as a general Citry feature. We are deferring production implementation and excluding this experiment from the main framework benchmark ranking. The prototype uses an application-owned Django ASGI route; any future comparison would need comparable streaming configurations for other frameworks and explicit disclosure of application-level optimizations. Route ownership is a separate question tracked in #143.
Measured opportunity
On the local 1,400-output page, one measured warm second-load pair compared the same experimental partial-SSR output delivered buffered versus streamed:
Measurement
Buffered
Streamed
Difference
Request start to framework-ready callback
392.2 ms
372.8 ms
−19.4 ms
Request start to layout-inclusive endpoint
404.3 ms
385.3 ms
−19.0 ms
Server request start to completed serialization
222.1 ms
230.0 ms
+7.9 ms
The streamed HTML started arriving about 52 ms before server serialization finished. Both responses were 2,482,204 uncompressed bytes and passed page/interaction checks. Their live IDs differ; byte parity was checked separately with fixed IDs.
These are one-pair observations, not a repeatable performance guarantee, a comparison against ordinary Citry rendering, or savings to add to earlier SSR results. The layout-inclusive endpoint schedules animation-frame callbacks directly from readiness, forces the fixed page/last-row geometry in the first callback, and records entry to the next callback. It includes pending layout but does not prove physical display paint. Server time above ends when the serializer finishes constructing the response. It includes scheduling and coordination/send waits, excludes final suffix delivery, and is not CPU time. Network conditions, compression and buffering can change the benefit.
What the prototype actually does
Render the entire Python component tree and produce the page HTML.
During serialization, identify and validate a document prefix containing the complete Vue-owned HTML host.
Send that prefix through the Django streaming response.
Finish preparing the Vue component definitions, occurrence data, dependencies and startup output while the browser can parse the prefix.
Send the remaining document.
This is two-stage serialization, not yielding each component as it renders. The prototype still constructs the complete final HTML string and checks that it begins with the prefix already sent; it does not establish a memory reduction. It covers the main-page GET, not Events responses.
The serializer supplies a private prefix-publishing callback. A worker publishes the prefix and waits for acknowledgement that ASGI sent it; a genuine async response iterator yields the prefix, lets serialization continue, then yields the suffix. Production should not inherit that research coordination machinery without a separate API design.
Illustrative desired API, not an existing Citry API:
# Citry provides chunks; the application owns URLs and responses.asyncdefpage_view(request):
tree=Page(user=request.user).render()
chunks=iter_serialized_chunks(tree)
returnStreamingHttpResponse(chunks, content_type="text/html")
Conceptual serializer:
asyncdefiter_serialized_chunks(tree):
plan=prepare_output(tree) # validate what must precede sendingyieldplan.initial_htmlyieldawaitplan.finish_browser_data_and_document()
The actual sync/async interface remains undecided. A generic iterator must preserve callback order and run application code once; it must not rerender the tree to recover from a rejected streaming path.
Work needed for production
Define which bytes are final before sending: head content, dependencies, root attributes, extension hooks, CSP/nonces/integrity and security validation must not later change emitted output. The prototype admits only a tightly controlled page/configuration.
Decide whether extensions need explicit declarations of what they inspect or mutate, and when unsupported cases use buffered output.
Define failures: before sending, buffered fallback may reuse the rendered tree; after sending, status/headers cannot be replaced and the response may need to terminate. No silent rerender or pretend rollback.
Handle disconnects, cancellation, backpressure and worker cleanup. Keep async streaming truly incremental; an adapter that buffers an iterator can erase the benefit.
Test compression, proxies and middleware that buffer responses. Buffered delivery must remain correct; early delivery is an optional benefit.
Generalize beyond this exact partial-SSR page, including dependency ordering, normal component callbacks, client startup and later server updates. Component-by-component streaming during rendering is a further capability, not proved here.
Measure repeated end-to-end outcomes, time to first content, memory and throughput before choosing a public API or default.
A useful implementation detail: the prototype initially validated the same four HTML regions per row before sending and again while preparing Vue data. Reusing validation only for the exact same immutable region strings within that serialization removed the second scan. If the objects differ, normal validation runs. This preserves validation rather than merely skipping it for speed.
Activity
JuroOravec commentedon Sep 23, 2026
(GPT Astra 5.6 medium)
Findings from the September 2026 performance experiments
Streaming is worth exploring as a general Citry feature. We are deferring production implementation and excluding this experiment from the main framework benchmark ranking. The prototype uses an application-owned Django ASGI route; any future comparison would need comparable streaming configurations for other frameworks and explicit disclosure of application-level optimizations. Route ownership is a separate question tracked in #143.
Measured opportunity
On the local 1,400-output page, one measured warm second-load pair compared the same experimental partial-SSR output delivered buffered versus streamed:
The streamed HTML started arriving about 52 ms before server serialization finished. Both responses were 2,482,204 uncompressed bytes and passed page/interaction checks. Their live IDs differ; byte parity was checked separately with fixed IDs.
These are one-pair observations, not a repeatable performance guarantee, a comparison against ordinary Citry rendering, or savings to add to earlier SSR results. The layout-inclusive endpoint schedules animation-frame callbacks directly from readiness, forces the fixed page/last-row geometry in the first callback, and records entry to the next callback. It includes pending layout but does not prove physical display paint. Server time above ends when the serializer finishes constructing the response. It includes scheduling and coordination/send waits, excludes final suffix delivery, and is not CPU time. Network conditions, compression and buffering can change the benefit.
What the prototype actually does
This is two-stage serialization, not yielding each component as it renders. The prototype still constructs the complete final HTML string and checks that it begins with the prefix already sent; it does not establish a memory reduction. It covers the main-page GET, not Events responses.
The serializer supplies a private prefix-publishing callback. A worker publishes the prefix and waits for acknowledgement that ASGI sent it; a genuine async response iterator yields the prefix, lets serialization continue, then yields the suffix. Production should not inherit that research coordination machinery without a separate API design.
Illustrative desired API, not an existing Citry API:
Conceptual serializer:
The actual sync/async interface remains undecided. A generic iterator must preserve callback order and run application code once; it must not rerender the tree to recover from a rejected streaming path.
Work needed for production
A useful implementation detail: the prototype initially validated the same four HTML regions per row before sending and again while preparing Vue data. Reusing validation only for the exact same immutable region strings within that serialization removed the second scan. If the objects differ, normal validation runs. This preserves validation rather than merely skipping it for speed.