Performance Architecture
Basalt is engineered to compete directly with Obsidian and outperform it at extreme scale. Every architectural decision is guided by three non-negotiable performance targets:
- Sub-16ms Keystroke Latency: Typing in the editor must never drop below 60fps, even in files with thousands of links and complex decorations.
- <800ms Time-to-Interactive (TTI): Opening a massive vault must present an interactive editor in less than a second.
- <150ms Full-Text Search: Querying across 5,000 to 25,000 notes returns ranked results almost instantly.
The Super-Large Vault Philosophy (≥25k Notes)
Testing software on small vaults of 500 notes produces misleading benchmarks. Power users frequently manage personal knowledge bases containing 25,000 to 50,000 notes, rich link graphs, and thousands of task items.
In Basalt:
- Performance claims and CI benchmark gates are evaluated against $\ge 25,000$-note fixtures.
- If a feature passes on 1k notes but degrades at 25k scale, it is considered broken.
Standing Performance Systems
1. Instant Two-Tier Boot (ADR-038)
Traditional PKM apps re-scan the vault directory on startup, blocking the user while spinning through tens of thousands of files. Basalt uses a decoupled two-tier boot strategy:
- Tier 1 (Instant Cache Mount): Upon launch, the Rust backend reads a compact pre-compiled bincode cache from disk into memory in <100ms. The file tree, active notes, and tags appear instantly.
- Tier 2 (Background Sync): A background Rayon thread pool scans file modification times (
mtime), reparsing only the specific files that changed while Basalt was closed.
App Launch
│
├── Tier 1 (<100ms) ────────► UI Rendered & Interactive (bincode cache)
│
└── Tier 2 (Background) ────► Rayon mtime scan & incremental diff reindex
2. Zero-AST Scanner with SIMD (ADR-034)
Constructing full Abstract Syntax Trees (ASTs) for thousands of markdown files consumes hundreds of megabytes of RAM and triggers heavy garbage collection.
Basalt uses a custom zero-AST byte scanner:
- Utilizes SIMD instructions (
memchr3) to find structural tokens (#,[[,- [,---) directly in raw UTF-8 byte buffers. - Extracts tags, links, headings, and task signifiers in a single linear pass without allocating intermediate syntax node objects.
3. Single-Pass Editor Decoration Pipeline (ADR-012, ADR-033)
CodeMirror 6 live-preview widgets (math, tags, checklists, callouts, embeds) are rendered in a single unified decoration pass with tight performance tunings:
- Change-Filtered Viewport Extensions: Viewport plugins like
taskListPluginandtagMarksPluginfilter incoming keystrokes using targeted regex guards (mightAffectTasks,mightAffectTags). Unaffected edits map existing decorations in $O(\Delta)$ time instead of re-traversing the viewport syntax tree. - In-Place DOM Recycling (
updateDOM): Custom block and inline widgets (TaskCheckboxWidget,InlineChipWidget,MathInlineWidget,MathBlockWidget) implementupdateDOMto mutate attributes in-place, bypassing expensive DOM teardowns and reconstructions on every keystroke. - Lezer AST Fast-Exits & Static Allocations: Leaf tokens (
Text,CodeText) immediately short-circuit child probes, range collections shortcut empty builds directly toDecoration.none, and static widgets (horizontalRuleWidget,codeFooterWidget) reuse cached singletons. - Layout Containment & Height Estimation: Heavy block widgets specify explicit
estimatedHeightto eliminate CodeMirror line-measurement reflows and scroll-anchor jumps. Widgets are wrapped in CSScontain: layout styleto prevent local mutations from triggering document-wide reflows.
Together, these optimizations keep in-viewport keystroke latency at 2.5ms mean / 3.3ms p95 even in 100 KB files.
4. Background Native Compute
All compute-intensive operations run on native OS worker threads in Rust:
- Tantivy & Nucleo Search: Full-text indexing and fuzzy matching execute off-thread.
- Graph Simulation: Velocity Verlet physics calculations run in background threads or WASM without stealing animation frames from the browser shell.
5. High-Fidelity UI Surface Virtualization: Theme Carousel
Modal UI surfaces that render rich graphic previews across dozens of options (e.g. the 48-theme coverflow carousel) implement strict DOM windowing and hardware containment to prevent micro-stutters:
- Layout & Paint Containment (
contain: layout style paint): Prevents complex 3D card transforms and theme token switches from invalidating the app shell's layout tree. - Selective
content-visibility: auto: Off-screen buffer cards defer layout and paint until scrolled into the active viewing frustum. - Lazy Active Indexing & Frame Gating: Arrow keys and trackpad gestures queue at a single requestAnimationFrame tick to eliminate queue thrashing during rapid tapping.
Empirical Performance (76 Themes Benchmark):
| Phase | commitP50 | p50 | p95 | Verdict |
|---|---|---|---|---|
open (modal mount & 1st paint) | — | 103ms | 134ms | Instant visual response (down from 204ms) |
step (arrow slide to next theme) | 9ms | 84ms | 94ms | Smooth frame commit (9ms < 16.6ms) |
tap-storm (10 rapid consecutive taps) | — | 529ms | 552ms | Zero frame drops or queue backlog |
6. Isolated Leaf Boundaries & Entry Preload Gates
Rich document leaves (whiteboards, kanban boards, node graphs, code editors) rely on specialized third-party runtimes (@excalidraw/excalidraw, @xyflow/react, mermaid, @codemirror/*). Allowing any of these to be statically imported on the initial startup path bloats the startup JavaScript bundle by multiple megabytes and degrades Time-to-Interactive (TTI).
Basalt enforces clean leaf boundaries through three standing constraints:
- Component-Free Constant Modules: Domain tokens, link prefixes, and format regexes are strictly isolated in leaf-level
constants.tsortypes.tsfiles, ensuring lightweight handlers (such as drag-and-drop or file resolution) never drag the heavy component tree into their importers. - Dynamic Service Gateways: Global and cross-feature orchestration services (
shared/useLeafServices.ts) dynamically load heavy leaf functions via on-demandimport()calls only when the specific action (such as generating an SVG export) is invoked. - Automated Entry Preload Gates: The build pipeline (
vite.config.ts) machine-checks all root entry chunk dependencies viaassert-clean-entry-preload, failing the build immediately if any forbidden heavy vendor is hoisted into<link rel="modulepreload">.
Empirical Startup & TTI Benchmarks (Linux Release Binary, Warm Boot):
| Metric | Leaked Preload Baseline | Clean Lazy Preload | + Warm Editor Prefetch | Latest (VaultDb + CSS Containment) |
|---|---|---|---|---|
| Root Entry Chunk Size | 710 KB (+ 4.1 MB leaked vendor) | 346 KB (isolated) | 346 KB (isolated) | 346 KB (isolated) |
Document Load (started → finished) | 467.9 ms | 128.2 ms | 134.0 ms | 47.1 ms |
Scripts Fetch + Eval (responseEnd → js_entry) | 436.0 ms | 300.0 ms | 300.0 ms | 260.0 ms |
| Shell Committed → First Painted Frame | 285.0 ms | 285.0 ms | 169.0 ms | 184.0 ms |
Splash Screen Duration (splash → painted) | 848.0 ms | 667.0 ms | 591.0 ms | 550.0 ms (-35.1% total) |
Webview TTI (nav start → painted) | 874.0 ms | 689.0 ms | 614.0 ms | 565.0 ms (Target Met: <800ms) |
Rust Preboot (rust:boot_total) | 87.8 ms | 66.5 ms | 82.0 ms | 68.2 ms (instant Tier 1 cache mount) |
7. Warm Boot vs. Cold Boot Prefetching
Rather than indiscriminately pre-fetching heavy leaf dependencies (which would penalize the cold vault selection screen) or deferring all chunk fetches until React mounts (which adds network/disk latency to first paint), Basalt inspects the cached workspace snapshot:
- Cold Boot (Vault Selection): The user has not selected a vault yet or opened an empty workspace. Zero editor/visualization chunks are prefetched. TTI to the vault picker remains minimal.
- Warm Boot (Saved Markdown Tab): When
shouldPrefetchEditor(boot)detects an active markdown document in the restored tab tree, the CodeMirror chunk is triggered concurrently duringinvoke("boot")resolution. This overlaps chunk parsing with React shell mounting, cutting frame 1 commit time from 285ms to 169ms without skeletons or layout shifts.
8. Document Open & First Paint Pipeline (ADR-033, ADR-052)
Opening a note cold involves disk I/O, frontmatter WASM initialization, CodeMirror EditorState creation, DOM line insertion, font shaping, and GPU rasterization.
To drive cold note open times well under 120ms without UI freezing or compositor ANRs, Basalt layers five concrete optimizations:
- Embedded ACID Vault Cache (
VaultDb): Document reads and metadata classification hit an embeddedredbdatabase directly, bypassing filesystem traversal and serializing zero-IPC extension classifications. - Pre-Warmed
EditorViewRecycling: Switching tabs or opening documents swaps state viaview.setState()on a persistent, pre-mountedEditorView. It never destroys or re-mounts the React DOM tree or reconfigures extensions. - CSS Layout Containment (
contain: layout style): The editor root enforces strict CSS layout boundaries. When CodeMirror inserts.cm-lineelements and queries line dimensions viagetBoundingClientRect(), reflow calculations stop at.cm-editorinstead of bubbling up to parent split panes, docks, or ribbon chrome. - Fast Text Shaping (
font-synthesis: none): Prevents browser text shapers (HarfBuzz, DirectWrite, CoreText) from executing algorithmic faux-bold and faux-italic glyph shearing during initial note layout. - Streamlined Cross-Platform Font Tokens: Standardizes
--sat-font-sansonInter, system-ui, -apple-system, sans-serif, eliminating multi-round Fontconfig/GDI fallback cache misses.
Empirical Note Open Benchmarks (Cold Document Mount & First Paint):
| Document Tier | Baseline (Pre-Containment) | Latest (VaultDb + CSS Containment) | Latency Reduction | Verdict |
|---|---|---|---|---|
| 1 KB Cold Open | 134.0 ms p50 / 158.0 ms p95 | 91.00 ms p50 / 104.00 ms p95 | -35 ms (~27% faster) | Sub-100ms instant open |
| 10 KB Cold Open | 142.0 ms p50 / 167.0 ms p95 | 90.00 ms p50 / 108.00 ms p95 | -40 ms (~28% faster) | Sub-100ms instant open |
| 100 KB Cold Open | 164.0 ms p50 / 192.0 ms p95 | 103.00 ms p50 / 111.00 ms p95 | -81 ms p95 (~42% faster) | Zero UI Freeze / 0 ANR |
Profiling & Bottleneck Hunting
Basalt includes built-in diagnostic and benchmarking tooling for catching regressions:
bun run dev:watchdog— Automatically tracks main-thread frame times and warns if any event handler blocks longer than 16ms.bun run dev:editor-benchmark— Measures live typing and scrolling latency across synthetic documents up to 100,000 words.- Dedicated surface benchmarks:
dev:bench:theme-carousel,dev:bench:search,dev:bench:note-open,dev:bench:graph,dev:bench:canvas,dev:bench:drawing, anddev:bench:all. - Phase timings via
editorBenchmarkState.debugto isolate exact millisecond costs between keystroke dispatch, DOM mutation, and layout paint.