Skip to content

[IMP] owl: render components once, without a virtual dom (prototype) - #2078

Draft
ged-odoo wants to merge 3 commits into
masterfrom
master-no-vdom
Draft

ged-odoo wants to merge 3 commits into
masterfrom
master-no-vdom

Conversation

@ged-odoo

@ged-odoo ged-odoo commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Prototype: components are rendered once, and render effects keep the dom up to date. There is no virtual dom and no re-rendering anymore.

The design is described in packages/owl-runtime/src/rendering/README.md, and tools/benchmark measures it against a vdom build.

How it works

  • Blocks. A template is instantiated once. The static dom of a block is cloned, and one render effect per block re-evaluates its dynamic values (attributes, properties) and writes the ones that changed. Event handlers and refs are set once.
  • Regions. t-if, t-foreach, t-out, components, slots, t-key and dynamic t-call/tags are regions: their render effect decides which sub-content exists, creates the missing one and disposes the other. Each sub-content has an owner (render effects, components, cleanups, nested owners), disposed with it.
  • Lists. Keyed rows are created once; their loop variables are signals, so a kept row only updates what reads a changed variable, and a reorder moves the existing nodes.
  • Props. A child is never re-rendered: the props effect of the parent updates its props in place (through the existing props signals), and the child's effects that read them re-run.
  • onWillStart. A component whose hooks return a promise shows an empty placeholder until it resolves. The initial mount() still waits for the whole initial tree.
  • Compiler. New code generator on top of the existing parser. A t-set creates a new context layer (a getter, computed when read), so closures created now and run later see the right values.
  • Removed. The blockdom vdom (list, multi, toggler, html, text), fibers, the scheduler, Suspense, onWillPatch, onPatched.

owl-core

  • Render effects (ComputationFlags.RENDER) are flushed before user effects, sorted by depth, so a region runs before what it contains (otherwise a child can update from a state its t-if is about to discard).
  • A render effect written to during its own run (RUNNING/DIRTY) runs again. Example: ErrorBoundary's onError sets the error signal while the boundary's t-if is still creating its content.

Tests

  • owl-core, owl-compiler and owl pass; build, type tests and formatting are clean.
  • tests/components/render_once.test.ts: 12 tests for the new behavior (ordering and self-write tests checked to fail without the owl-core changes).
  • owl-runtime: 1098 passed, 281 failed. About 230 failures use what no longer exists (blockdom vdom tests 117, render() helper 52, patch() 23, onWillPatch/onPatched 21, Suspense 9, 2 files importing fibers/scheduler). The others are behavior differences: t-set is immutable and lazy (no leak out of t-if, no accumulation across iterations, "render counters" based on t-set stop firing), updates land in the next microtask instead of the next frame, refs are bound before mount; Portal position and t-call-block are not implemented.

Benchmark

node tools/benchmark/run.mjs 3.0.0-beta.1=<beta>/dist/owl.iife.js master-no-vdom=packages/owl/dist/owl.iife.js: headless Chrome, 1000 keyed rows, median ms from the state change to the updated dom (the beta's frame wait replaced by a microtask), about 20% of variation between runs:

operation 3.0.0-beta.1 this branch
update every 10th row 1.5 0.3
select row 1.2 0.8
remove row 1.5 1.3
swap rows 1.1 1.8
clear rows 0.8 1.9
create 1000 rows 5.7 8
replace all rows 6.8 10.4

Updates are faster; creating and disposing rows costs more (an owner, signals and an effect per block and per t-out). A next step would be to handle a plain t-out text in the effect of its block. The unminified bundle is about 16% smaller (197 KB vs 235 KB).

Before this commit, a component re-renders its whole template when
something it read changes: a new block tree is built and diffed against
the previous one, through fibers committed on animation frames.

This commit renders each template once. A block is cloned once, and one
render effect updates the attributes and properties that changed; t-if,
t-foreach, t-out, components and slots are regions owning their
sub-contents, which they create or dispose. Render effects are flushed
before user effects, parents first, and one written to during its run
runs again. Props are updated in place, a component with an async
onWillStart shows a placeholder until it resolves, and fibers, the
scheduler, Suspense, onWillPatch and onPatched are removed.
Before this commit, every region (t-if, t-out, ...) adds an anchor text
node and a t-out text is created in its own owner, a list reads its
collection three times per update and creates four signals per row, and
clearing a list removes its rows one by one. Creating, swapping and
clearing 1000 rows is 1.7 to 2.7 times slower than with the vdom.

This commit inserts a new region content before the previous one instead
of using an anchor, creates texts and markup without an owner, reads the
collection once into plain arrays, creates the row signals of the loop
variables in use only, and clears a list that is alone in its parent at
once.
…time

Before this commit, the design of the render-once prototype is only
described in the code, and there is no way to measure it against the
vdom runtime.

This commit adds tools/benchmark: a page creating, updating, selecting,
swapping, removing and clearing 1000 keyed rows, run in headless Chrome
for each given owl build, with results against 3.0.0-beta.1. It also
adds the design of the runtime in owl-runtime/src/rendering/README.md.

This branch has not been deployed

No deployments
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