Architecture
이 콘텐츠는 아직 번역되지 않았습니다.
Lumen Charts is built around four engineering principles established in docs/design.md:
- Per-frame work is bounded by visible pixels; per-tick work is constant.
- Algorithms (level of detail, incremental indicator state) come before low-level optimization.
- Every optimization must pass a measured browser benchmark gate before landing.
- Zero host-page requirements. Workers, WebGPU, WebGL2, and
SharedArrayBufferare all optional and fall back cleanly.
Process split
Section titled “Process split”Main thread Data engine (worker; time-sliced on main if blocked)┌───────────────────────────────┐ ┌───────────────────────────────────┐│ API & Datafeed adapter │ bars, │ Chunked columnar store (owner) ││ Model: TimeScale, PriceScale │ ticks │ LOD pyramid (16, 64, 256, ...) ││ Window cache: visible range │──────▶│ Indicator engine (full & ││ ±2 screens & coarse LODs │◀──────│ incremental, holds state) ││ View: f32 coordinate buffers │ snap- │ Mark stores (heatmap & scatter) ││ Renderer: Canvas 2D + WebGL2/ │ shots,│ Custom indicator ES modules ││ WebGPU mark layers │patches└───────────────────────────────────┘│ Input, hit testing, drawings │└───────────────────────────────┘- Single owner: only the data engine owns full bar history, mark history, and indicator state. The main thread keeps a sliding window around the viewport plus coarse LOD levels, swapping in raw bars asynchronously after fast scrolls.
- Atomic tick patches: a live tick goes to the engine, which responds with one patch carrying the updated tail bar, affected LOD buckets, and the updated tail value of every indicator together — bars and indicators never disagree by a frame.
- Identical asynchronous interface: whether running inside a Web Worker or time-sliced in short main-thread slices, calling code uses the exact same protocol.
Chunked columnar store & LOD pyramid
Section titled “Chunked columnar store & LOD pyramid”- Bars are stored in fixed 8,192-row chunks of
Float64Arraycolumns (time,open,high,low,close,volume) inside a deque, giving O(1) prepends and appends with stable signed global indexes. - Under a
memoryLimitwith a datafeed, distant chunks are evicted while retaining time summaries and checksums so refetched chunks are validated on return. - Coarse level-of-detail pyramids group bars by powers of 4 starting at 16 (
16, 64, 256, ...), preserving first open, highest high, lowest low, last close, and min/max extremes for line and indicator outputs.
Layered rendering & GPU mark backends
Section titled “Layered rendering & GPU mark backends”- Three Canvas 2D pane layers (series, drawings, crosshair/overlay) plus dedicated axis canvases minimize redraw area. When a tick changes only the tail bar on a GPU-rasterized canvas,
redraw: 'auto'repaints only the affected device-pixel columns. - Mark series (
heatmapandscatter) render through per-chart selectable backends:webgl2(default, shared GL context per document),webgpu(compute/instanced specialized paths with automatic WebGL2 and Canvas 2D fallback), orcanvas2dpixel buffers. - Shared page resources: multiple charts on one page share a bounded worker pool, a single two-phase
requestAnimationFrameloop (all DOM reads before all writes), oneResizeObserver, oneIntersectionObserver(pausing off-screen draws), and shared time-zone offset tables.
Deep-dive design documents
Section titled “Deep-dive design documents”The repository preserves the full design document and per-stage decision records: