Skip to content

armgit / BUI

Public Imported from GitHub
0

Blender's GPU Accelerated UI, Decoupled from it's original codebase. Supports Rust, Python, JS, React, C & C++. Twice as good as GPUI

feat: virtual list video

Preetham Pemmasanid409cd6d7f4f
diff --git a/website/public/videos/Virtual_list.mp4 b/website/public/videos/Virtual_list.mp4
new file mode 100644
index 0000000..0a2b893
Binary files /dev/null and b/website/public/videos/Virtual_list.mp4 differ
diff --git a/website/src/components/docs/LazyVideo.astro b/website/src/components/docs/LazyVideo.astro
new file mode 100644
index 0000000..349da92
--- /dev/null
+++ b/website/src/components/docs/LazyVideo.astro
@@ -0,0 +1,83 @@
+---
+/**
+ * A video that is not downloaded until the reader clicks it.
+ *
+ * <LazyVideo src="videos/Virtual_list.mp4" shot="chat-list" alt="…" caption="…" />
+ *
+ * The page ships only the poster (a screenshot, light/dark like <Figure>) and a play button.
+ * No <video> element, and so no request for the file, exists until the click; then the
+ * poster is replaced by a <video> that starts playing. `shot` or `poster` give the poster.
+ */
+import { href } from "../../lib/docs";
+import ThemedImage from "./ThemedImage.astro";
+
+interface Props {
+ src: string;
+ alt: string;
+ caption?: string;
+ shot?: string;
+ poster?: string;
+ /** Size of the file, shown on the button so the click is an informed one, e.g. "15 MB". */
+ size?: string;
+}
+
+const { src, alt, caption, shot, poster, size } = Astro.props;
+if (!shot && !poster) throw new Error(`<LazyVideo src="${src}">: give shot or poster.`);
+---
+
+<figure class="figure not-prose border border-border" data-reveal>
+ <div class="lazy-video figure-stage hatch flex justify-center px-4 py-6 sm:px-8 sm:py-9" data-src={href(src)} data-label={alt}>
+ <button type="button" class="lazy-video-btn relative block max-w-full cursor-pointer border-0 bg-transparent p-0" aria-label={`Play video: ${alt}`}>
+ <ThemedImage alt="" shot={shot} light={poster} dark={poster} loading="lazy" class:list={["img-outline h-auto max-w-full figure-img"]} />
+ <span class="play absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 items-center gap-2 bg-primary px-4 py-2 text-[14px] font-semibold text-primary-ink shadow-lg">
+ <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true"><path d="M2 1l11 6-11 6z" fill="currentColor"></path></svg>
+ Play video{size ? ` (${size})` : ""}
+ </span>
+ </button>
+ </div>
+ {caption && <figcaption class="border-t border-border bg-surface px-4 py-2.5 text-[13px] leading-5 text-muted [&_code]:font-mono [&_code]:text-[0.9em]" set:html={caption} />}
+</figure>
+
+<style>
+ .figure-stage {
+ background-color: var(--stage);
+ }
+ .figure-img {
+ box-shadow: var(--shadow);
+ }
+ .lazy-video-btn:focus-visible {
+ outline: 2px solid var(--color-primary);
+ outline-offset: 3px;
+ }
+ .lazy-video-btn:hover .play {
+ filter: brightness(1.08);
+ }
+ .lazy-video :global(video) {
+ display: block;
+ max-width: 100%;
+ height: auto;
+ box-shadow: var(--shadow);
+ }
+</style>
+
+<script>
+ // Nothing is requested until the click: the <video> does not exist before it.
+ document.querySelectorAll<HTMLElement>(".lazy-video").forEach((box) => {
+ const btn = box.querySelector<HTMLButtonElement>(".lazy-video-btn");
+ btn?.addEventListener(
+ "click",
+ () => {
+ const video = document.createElement("video");
+ video.controls = true;
+ video.autoplay = true;
+ video.playsInline = true;
+ video.preload = "auto";
+ video.setAttribute("aria-label", box.dataset.label ?? "Video");
+ video.src = box.dataset.src ?? "";
+ btn.replaceWith(video);
+ video.play().catch(() => {}); // autoplay may be refused; the controls are there
+ },
+ { once: true },
+ );
+ });
+</script>
diff --git a/website/src/components/docs/index.ts b/website/src/components/docs/index.ts
index 5ac9ea4..2e52e2d 100644
--- a/website/src/components/docs/index.ts
+++ b/website/src/components/docs/index.ts
@@ -7,6 +7,7 @@ export { default as CardGrid } from "./CardGrid.astro";
export { default as ComingSoon } from "./ComingSoon.astro";
export { default as Compare } from "./Compare.astro";
export { default as Figure } from "./Figure.astro";
+export { default as LazyVideo } from "./LazyVideo.astro";
export { default as Hatch } from "./Hatch.astro";
export { default as Kbd } from "./Kbd.astro";
export { default as LangTabs } from "./LangTabs.astro";
diff --git a/website/src/content/docs/rust/virtual-list.mdx b/website/src/content/docs/rust/virtual-list.mdx
index 2515098..7cbedbf 100644
--- a/website/src/content/docs/rust/virtual-list.mdx
+++ b/website/src/content/docs/rust/virtual-list.mdx
@@ -17,6 +17,14 @@ A chat is the hard case for a list. Every message has its own height (a one-word
caption="A chat opened at its newest message, one message selected (<code>examples/site_chat.rs</code>)."
/>
+<LazyVideo
+ src="videos/Virtual_list.mp4"
+ shot="chat-list"
+ size="15 MB"
+ alt="Scrolling a chat with ten million messages: the list stays smooth while the scrollbar jumps through history"
+ caption="The list in motion. The video downloads only when you press play."
+/>
+
## A chat in 20 lines
You give the list your messages and keep its state in an entity. `chat_list` is the element; a click on a message selects it.
@@ -128,6 +136,21 @@ An `ItemSource` is `len`, the text bytes in a range (so an estimate needs no per
## Measured
+### What these benchmarks are
+
+Every chart below answers one question: **how much does it cost to show a long chat, and does that cost grow with the number of messages?** The chat is a list of messages of different heights (wrapped text, images, run headers), scrolled continuously in a real window.
+
+- **The three libraries.** `blenderui-vlist` is this crate. `gpui list` is the variable-height list that ships with gpui. `gpui-component virtual_list` is the one in gpui-component 0.9.0. All three show the same messages in the same window on the same gpui.
+- **The sizes.** 100 messages is a normal chat. 1,000,000 and 10,000,000 are the limit cases: an archive, a log viewer, a support inbox.
+- **Scroll frame.** The time the main thread spends from the start of a frame's render to the end of paint while the list is being scrolled. It leaves out the GPU and the wait for the screen's refresh. Lower is smoother; a 60 Hz screen allows 16.7 ms.
+- **Memory above an empty window.** How much the process grows when it builds and shows the list, **not counting the messages themselves**. At 10M messages the messages are a 1.1 GB file on disk that every library reads from, so this is the cost of the list's own bookkeeping (positions, heights, caches). An app that keeps its messages in memory pays for them on top, in any library.
+- **Setup time.** From handing the list its messages to being ready to draw the first frame.
+- **The index chart** compares the list's height index with the simplest approach, a flat array of running totals, to show what each costs when one message's height changes (an image loads, text is edited, the window is resized).
+
+All numbers are on one laptop (below), median of 3 runs, release builds. They show how the libraries scale on that machine, not absolute speed on yours; the code to rerun them is in `blenderui-vlist/examples` and `blenderui-vlist-gpui`.
+
+### Results
+
All numbers are on a Ryzen 7 5800U laptop (8 cores, 16 GB), Windows 11, release builds, on AC power with other programs open. They are medians of 3 runs, one process per run. The code is in `blenderui-vlist/examples` and `blenderui-vlist-gpui`.
**The index against a flat `Vec` of running totals** (`bench_core`), the simplest correct implementation. Both are O(1) per item to read; the flat `Vec` pays O(n) to change a height.
diff --git a/website/src/data/bench.ts b/website/src/data/bench.ts
index 9452036..efa1cb6 100644
--- a/website/src/data/bench.ts
+++ b/website/src/data/bench.ts
@@ -643,7 +643,7 @@ export const charts = {
"vlist-memory": {
kind: "groups",
title: "Variable-height list: memory above an empty window",
- subtitle: "Real gpui window, resident memory after the list is built and scrolled",
+ subtitle: "Real gpui window: how much the process grows for the list, not counting the messages (at 10M they are a file on disk)",
unit: "MB",
better: "lower",
headline: { value: "6 MB", text: "for 10 million messages (gpui list: 910 MB)" },