Skip to main content

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 taskListPlugin and tagMarksPlugin filter 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) implement updateDOM to 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 to Decoration.none, and static widgets (horizontalRuleWidget, codeFooterWidget) reuse cached singletons.
  • Layout Containment & Height Estimation: Heavy block widgets specify explicit estimatedHeight to eliminate CodeMirror line-measurement reflows and scroll-anchor jumps. Widgets are wrapped in CSS contain: layout style to 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.

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):

PhasecommitP50p50p95Verdict
open (modal mount & 1st paint)—103ms134msInstant visual response (down from 204ms)
step (arrow slide to next theme)9ms84ms94msSmooth frame commit (9ms < 16.6ms)
tap-storm (10 rapid consecutive taps)—529ms552msZero 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.ts or types.ts files, 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-demand import() 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 via assert-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):

MetricLeaked Preload BaselineClean Lazy Preload+ Warm Editor PrefetchLatest (VaultDb + CSS Containment)
Root Entry Chunk Size710 KB (+ 4.1 MB leaked vendor)346 KB (isolated)346 KB (isolated)346 KB (isolated)
Document Load (started → finished)467.9 ms128.2 ms134.0 ms47.1 ms
Scripts Fetch + Eval (responseEnd → js_entry)436.0 ms300.0 ms300.0 ms260.0 ms
Shell Committed → First Painted Frame285.0 ms285.0 ms169.0 ms184.0 ms
Splash Screen Duration (splash → painted)848.0 ms667.0 ms591.0 ms550.0 ms (-35.1% total)
Webview TTI (nav start → painted)874.0 ms689.0 ms614.0 ms565.0 ms (Target Met: <800ms)
Rust Preboot (rust:boot_total)87.8 ms66.5 ms82.0 ms68.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 during invoke("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:

  1. Embedded ACID Vault Cache (VaultDb): Document reads and metadata classification hit an embedded redb database directly, bypassing filesystem traversal and serializing zero-IPC extension classifications.
  2. Pre-Warmed EditorView Recycling: Switching tabs or opening documents swaps state via view.setState() on a persistent, pre-mounted EditorView. It never destroys or re-mounts the React DOM tree or reconfigures extensions.
  3. CSS Layout Containment (contain: layout style): The editor root enforces strict CSS layout boundaries. When CodeMirror inserts .cm-line elements and queries line dimensions via getBoundingClientRect(), reflow calculations stop at .cm-editor instead of bubbling up to parent split panes, docks, or ribbon chrome.
  4. 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.
  5. Streamlined Cross-Platform Font Tokens: Standardizes --sat-font-sans on Inter, system-ui, -apple-system, sans-serif, eliminating multi-round Fontconfig/GDI fallback cache misses.

Empirical Note Open Benchmarks (Cold Document Mount & First Paint):

Document TierBaseline (Pre-Containment)Latest (VaultDb + CSS Containment)Latency ReductionVerdict
1 KB Cold Open134.0 ms p50 / 158.0 ms p9591.00 ms p50 / 104.00 ms p95-35 ms (~27% faster)Sub-100ms instant open
10 KB Cold Open142.0 ms p50 / 167.0 ms p9590.00 ms p50 / 108.00 ms p95-40 ms (~28% faster)Sub-100ms instant open
100 KB Cold Open164.0 ms p50 / 192.0 ms p95103.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, and dev:bench:all.
  • Phase timings via editorBenchmarkState.debug to isolate exact millisecond costs between keystroke dispatch, DOM mutation, and layout paint.