04 — Beyond CSS: Flat-Array O(N) Layout & Pluggable Window Managers for Millions of Users
04 — Beyond CSS: Flat-Array O(N) Layout & Pluggable Window Managers for Millions of Users
2026-11-19 · Awesome-OS Development History
If you ask why desktop apps feel sluggish at 120 Hz, why Electron eats gigabytes of RAM just to draw three panes, and why millions of users are forced to choose one rigid desktop paradigm (floating windows on Windows/macOS, or recompiling a Linux compositor to try tiling), the answer traces back to the same 1990s mistake: pointer-chasing layout trees coupled to a single hardcoded window manager.
Awesome-OS replaces both layers with one small, portable, zero-dependency engine: @awesome-os/b8g-layout.
1. Why Chrome / CSS / DOM Failed as an OS UI Substrate
The browser DOM was designed to flow static hypertext documents in 1994, not to compose live operating-system workspaces at 120 FPS:
- Pointer-Chasing Heap Fragmentation: Every DOM element, CSSOM rule, and
LayoutObjectis a separate heap allocation connected by pointers. Traversing 10,000 UI nodes trashes CPU L1/L2 caches before a single pixel reaches the GPU. - Pathological O(N2) Reflow Cascades: Nested
flex/grid/ intrinsic-sizing queries trigger multi-pass layout thrashing (getBoundingClientRect()-> dirty style -> full subtree reflow). One badge update in a sidebar can stall the entire frame budget. - Global CSS Cascade & Specificity Wars: Styles leak globally across unrelated components, forcing layers of shadow DOM, CSS-in-JS runtimes, and build-time bundlers just to achieve isolation.
- Forced Single Window Manager: Legacy OSes bake one windowing metaphor into the shell. Windows and macOS lock users into overlapping floating rectangles; i3/Hyprland lock users into BSP tiling; Niri locks users into a scrolling strip; Figma/Miro lock users into an infinite 2D canvas. Switching workflows requires switching operating systems or rewriting apps.
2. Two-Sweep O(N) Flat-Array Layout -> 48B/Quad SabGpuQuadSlab
In packages/@awesome-os/b8g-layout/src/flat-layout.mts, there is no DOM tree, no CSS cascade, and no heap-allocated layout nodes.
Every UI frame lives in a contiguous, cache-friendly flat array (pre-order parent-before-child index order) using just four sizing primitives inspired by Clay / Morphorm:
| Sizing Mode | Semantics | Typical Use |
|---|---|---|
FIXED |
Exact pixel extent (value) |
Toolbars, icons, status pills, fixed dividers |
FIT |
Intrinsic minimum bounding box of children + padding/gaps | Buttons, badges, auto-sized headers |
GROW |
Absorbs remaining parent axis space proportionally (weight) |
Main workspace panes, flexible editor columns |
PERCENT |
Deterministic fraction of parent inner extent (0..1) |
Split ratios, responsive sidebars |
The Deterministic Two-Sweep Pass
flowchart LR
FLAT["Contiguous Flat Layout Array<br/>(Pre-order parent-before-child)"] --> UP["Sweep 1: Bottom-Up (i = N-1 -> 0)<br/>Compute FIT intrinsic sizes + padding/gaps"]
UP --> DOWN["Sweep 2: Top-Down (i = 0 -> N-1)<br/>Distribute FIXED, PERCENT & GROW extents<br/>Write final (x, y, w, h) rects"]
DOWN --> SLAB["SabGpuQuadSlab (48 B / quad)<br/>Zero-copy GPU upload -> b8g_render_v1"]
- Strictly O(N) linear scans: One reverse loop (
N - 1down to0) resolves everyFITsize from leaves up to the root; one forward loop (0up toN - 1) resolvesFIXED,PERCENT, andGROWdistribution plus exact screen(x, y, w, h)coordinates. - Direct 48B/Quad GPU Packing: Resolved rects emit directly into the 48-byte-per-quad
SabGpuQuadSlablayout consumed by both nativeb8g-gfx-host(wgpu+winit+glyphon) and browser WebGPU (SAB_UI_QUAD_WGSL) — zero intermediate virtual DOM, zero serialization, zero GC pressure. - Strictly Portable: Zero
node:*imports anderasableSyntaxOnly: trueclean, so the exact same solver runs on bare-metal/UEFI, native desktop, browser workers, and WASI.b8ecells.
3. Four Pluggable Array-Intersection Window Managers (1 Click, Zero App Rewrites)
Because every Awesome-OS surface (a V8 isolate, a WASI .b8e cell, a terminal, or a CoW branched app frame) is just a flat array descriptor (SurfaceDescriptor with id, preferred bounds, min dimensions, and focus state), the Window Manager is no longer a monolithic daemon.
It is a pure O(N) projection function over the surface array in packages/@awesome-os/b8g-layout/src/window-managers.mts:
Mode (WindowManagerMode) |
Inspiration | Geometry & User Guarantee |
|---|---|---|
infinite-canvas |
Figma / spatial desktop | 2D pan/zoom spatial projection (sx = (x - cameraX) * zoom + vp.x) with automatic viewport frustum culling (visible). |
scroll-strip (default in WindowLayoutSection) |
Niri scrolling WM | Infinite horizontal strip of full-height columns (clamp(preferredW, minW, vp.width - 2*gap)), offset by scrollX. Windows never get squished, no matter how many apps you open. |
tile-bsp |
Hyprland / i3 | Recursive binary space partitioning alternating longest-axis splits with uniform gap — zero wasted pixels, zero overlaps. |
floating |
Classic desktop | Cascaded overlapping windows with the focused surface automatically elevated to the highest zIndex. |
Switching between all four paradigms is a single call: nextWindowManagerMode(current) (infinite-canvas -> scroll-strip -> tile-bsp -> floating) fed into computeWindowManagerLayout(mode, surfaces, viewport).
Zero app rewrites. Zero process restarts. Zero lost state. Every running Section and CoW frame keeps its exact memory slice and capability token while its projected screen geometry snaps instantaneously to the user's preferred mental model.
4. Live Integration: sections/canvas-branch & sections/window-layout
We wired @awesome-os/b8g-layout directly into both the portable schema layer and our live native wgpu canvas:
- Persisted User Preference (
sections/window-layout/index.mts):
WindowLayoutSection (s.sqlite) now stores wmMode (default 'scroll-strip') alongside setWmMode and updateLayout ops — strictly zero node:* imports and erasableSyntaxOnly: true. Any Intersection composed with WindowLayoutSection automatically persists the user's chosen Window Manager across restarts.
- One-Click Live WM Switching in Native
wgpu(sections/canvas-branch/):
In branch-runtime.host.mts and cli.host.mts, the native wgpu + winit + glyphon Infinite CoW Canvas toolbar now exposes a live [WM: canvas|strip|bsp|float] button (toolbar:wm-cycle).
- Clicking
[WM: ...]cyclesinfinite-canvas->scroll-strip->tile-bsp->floatingand immediately recomputes every live/cold branched frame throughcomputeWindowManagerLayout(...). - In
scroll-strip,ArrowLeft/ArrowRightand mouse scroll smoothly glide along the horizontal column strip without ever squishing a frame. - In
tile-bsp, every branched frame tiles edge-to-edge with zero overlap; infloating, clicking any frame elevates it to topzIndexwhile preserving the strictO(1)lazy hydration invariant (hydrated <= 1).
5. Try It Yourself
# Launch the native wgpu Infinite CoW Canvas and click [WM: canvas] in the top toolbar
& "e:\awesome-os\packages\@awesome-os\bin-shim\bin\node.ps1" --experimental-strip-types `
e:\awesome-os\sections\canvas-branch\cli.host.mts --window
# Inspect or switch persisted WM mode via dev-catalog
bin\dev-catalog.ps1 invoke section.window-layout setWmMode '{"wmMode":"tile-bsp"}'
Related anchors: packages/@awesome-os/b8g-layout/src/index.mts · flat-layout.mts · window-managers.mts · sections/window-layout/index.mts · sections/canvas-branch/branch-runtime.host.mts