Crates.io | librender |
lib.rs | librender |
version | 0.1.0 |
source | src |
created_at | 2024-10-23 19:11:21.063925 |
updated_at | 2024-10-23 19:11:21.063925 |
description | librender bytecode IR bindings |
homepage | https://github.com/elricmann/render |
repository | https://github.com/elricmann/render |
max_upload_size | |
id | 1420507 |
size | 1,145,075 |
Experimental JavaScript UI rendering library. Render uses a lightweight stack-based VM with minimal opcodes to encode DOM trees and run DOM operations either immediately or in retained mode (by diffing and patching bytecodes). Components are defined as views that serialize their attributes and children into Uint8Array
instances.
npm install librender
Refer to main.tsx for basic usage.
View
- view instance serializerText
- static text view with titleButton
- static button with labelContainer
- dynamic view with optional attributes (e.g. tag name)Container
)attr
method), deprecate opcode for inline stylesButton
)OPCODE_CREATE_ELEMENT
)OPCODE_SET_ATTRIBUTE
)OPCODE_APPEND_CHILD
)OPCODE_TEXT_NODE
)innerHTML
with in-memory string sourceOPCODE_APPEND_SIBLING
)OPCODE_EVENT_LISTENER
, requires __eventStore
)requestAnimationFrame
createBytecodeStream
, unsafe_streamBytecodeToVM
)ThreadView
)Render relies on views to return byte arrays with exact alignment of data values and offsets. The VM does not fix program inputs which is why views form safe high-level wrappers representing extendable components. Aside, the default settings are supposed to be configurable.
Portability is the primary goal of this library. I wrote librender
expecting that there could be a single optimizing bytecode IR for various web-based rendering libraries. To this effect, there is an imperative-procedural approach when defining view methods that correspond to raw bytecode.
The VM does not fully take the role of a DOM-based model and opcodes are only limited to DOM operations where inputs are serializable (e.g. event handlers are not serializable). It lacks features like pausability and resumability, async batch streaming, per-batch scheduling, and virtual prioritization, that could essentially improve rendering.
The structural description of the VM is:
nodeCount
is a counter that allows managing the nodeIndexStack
in the DOM operationsWebAssembly modules are loaded as view slices into an array buffer representing a linear memory model. Since modules are precompiled, the bytecode could target librender
with virtually no overhead. This would imply that optimizing the VM itself from the JavaScript source would improve existing programs without introducing layers of indirection.
With this enabled, various high-level libraries targeting the bytecode can be used as microfrontends with predictability. Currently, librender
is barely useable so this will require major effort to put in place. Additionally, certain data structures can be linearly represented for uniformity, e.g. C-like structs with offsets require no deallocation in WebAssembly. Growing memory is as easy as incrementing a pointer.
Portability allows loading .bin
files through a shared worker, which could be useful for monolithic SPAs that depend on server endpoints to fetch and render data in the main UI thread for client-side rendering.
Render does not provide unique insights into the approach rendering is done or criteria for commiting DOM nodes for painting. Other libraries such as React (scheduling model) and GlimmerVM (opcode-based rendering) are to be considered prior art in this regard.
Copyright © 2024 Elric Neumann. MIT License.