Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andtools/benchmarkmeasures it against a vdom build.How it works
t-if,t-foreach,t-out, components, slots,t-keyand dynamict-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.mount()still waits for the whole initial tree.t-setcreates a new context layer (a getter, computed when read), so closures created now and run later see the right values.onWillPatch,onPatched.owl-core
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 itst-ifis about to discard).RUNNING/DIRTY) runs again. Example: ErrorBoundary'sonErrorsets the error signal while the boundary'st-ifis still creating its content.Tests
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).render()helper 52,patch()23,onWillPatch/onPatched21, Suspense 9, 2 files importing fibers/scheduler). The others are behavior differences:t-setis immutable and lazy (no leak out oft-if, no accumulation across iterations, "render counters" based ont-setstop firing), updates land in the next microtask instead of the next frame, refs are bound beforemount; Portalpositionandt-call-blockare 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: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 plaint-outtext in the effect of its block. The unminified bundle is about 16% smaller (197 KB vs 235 KB).