TypeScriptPerformanceTauriMindloft

Benchmarking a 2,350-Node Mindmap: Cold-Open Panic, BVH Connectors, GPU Zoom, and macOS Close-Hide

Stress-testing Mindloft with a 3-sheet, 2,350-node map exposed a Finder cold-open panic, slow Loro incremental projections, a 2,295ms connector pass, janky wheel zoom, and a macOS close-to-hide inert deadlock.

Before claiming Mindloft handled large maps, I built a stress-test .ramilo file: 3 sheets, 2,350 nodes total, with 2,050 nodes, 65 cross-node connectors, 224 images, 19 boundaries, and 14 summaries packed onto Sheet 1 alongside Markdown and LaTeX formulas.

Double-clicking it on macOS crashed on launch. Once fixed, renaming the root node took 236 ms, hitting Tab to add a child took 466 ms, connector routing burned 2,295.7 ms, and trackpad zooming stuttered on every frame.

Between v0.7.2 and v0.7.4, we rebuilt the macOS window handshake, Loro’s incremental projection path, connector collision geometry, GPU-composited zoom, and a cross-platform minimap.

v0.7.2: Closing a macOS Window Froze the WebView on Reopen

One desktop bug predated the stress test: closing a macOS window with the red button and clicking the Dock icon brought back a frozen UI — everything rendered, nothing clicked or typed.

To prevent data loss on close, apps/desktop/src-tauri/src/lib.rs and apps/web/src/product/desktop-save.ts run a CloseHandshake. On WindowEvent::CloseRequested, Rust calls api.prevent_close() and emits before-close with an incrementing epoch. The frontend sets document.body.inert = true, blocks input events while flushing to disk, and replies with confirm_close({ epoch }).

On Windows, the window is destroyed next. On macOS, red-button close only calls win.hide(), leaving the WebView alive — still locked in document.body.inert = true because no resume event ever fired.

Unlocking inside confirm_close would leave a race window during Cmd+Q where late keystrokes bypass both blocking and disk flush. Instead, Rust now calls mark_hidden(epoch) after win.hide() to emit close-hidden, and reveal_main_window idempotently re-emits it across RunEvent::Reopen, RunEvent::Opened, and the Dock menu. The frontend only clears inert when event.payload.epoch === activeEpoch. We also tightened CloseHandshake::defer to DeferOutcome::Allowed(u64) checking *acknowledged == pending so stray close events cannot consume a pending Quit acknowledgment.

v0.7.3: Finder Cold-Open Panicked Before .setup() Ran

Double-clicking examples/stress-test-2350.ramilo from Finder triggered an immediate crash in apps/desktop/src-tauri/src/lib.rs.

PendingOpenFiles had been registered inside .setup() via app.manage(...). Launching normally worked because windows open after .setup(). Cold-launching via a file association delivers RunEvent::Opened before RuntimeRunEvent::Ready (when .setup() executes), so app.state::<Arc<PendingOpenFiles>>() panicked on missing state. Moving pending_open registration onto tauri::Builder::default().manage(...) and switching handlers to handle.try_state(...) resolved it (50/50 Rust tests passing).

Loro Write Path and 2,295 ms Connector Routing

Profiling single edits on the 2,350-node file inside packages/document-core/src/loro/loro-document-kernel.ts exposed three hidden fallbacks:

  1. Any node with assetIds skipped incremental projection: projectIncremental returned null and rebuilt all 2,350 nodes. Because the root node held images, node.setTitle on the root took 236.0 ms. Supporting partial updates for assetIds nodes cut that to 16.33 ms.
  2. No fast path for single-node creation: Adding a child or sibling (isPureNodeCreate) now runs writePureNodeCreate plus incremental projection, dropping node.createChild from 466.1 ms to 34.49–36.85 ms. (To be explicit: undo/redo for node creation did not yet use this fast path and stayed around 753.57 ms / 764.43 ms.)
  3. Redundant full-tree verification: When validatedFromBatch is true after incremental projection, writeLocal skips repeating same(before, after) and assertNativeUnicode(after).

On Sheet 1 (2,050 nodes, 65 connectors), computeSheetRelationGeometries in packages/layout/src/connectors.ts originally took 2,295.7 ms due to O(R × N) obstacle checks and recursive Bézier object allocations. Rewriting it around a flat Float64Array AABB BVH (ObstacleIndex), depth-4 pre-split subcurves with stack-only cubicIntersectsScalar, branch-and-bound pruning, and Pass 2 curve reuse dropped layout time to 33.89 ms on web/desktop (5.36 ms for labels) and 133.97 ms cold on mobile.

Viewport Culling, GPU Zoom, and the Cross-Platform Minimap

To keep rendering fast, web/desktop (mindmap-panel.tsx, outline-panel.tsx) added hysteresis viewport culling above 200 nodes (bucket sizes 512 below 0.45 zoom, 256 above), a windowed <svg viewBox>, and outline virtualization at >= 400 rows. mindmap-zoom-gesture.ts stopped triggering React re-layouts on every wheel event: active gestures tag data-zooming="true" (will-change: transform), batch translate3d + scale in requestAnimationFrame, and settle exact scroll offsets once via computeGestureSettleScroll (keeping 119 culled nodes steady across 50%–90% zoom in Chromium 1440×900 with <= 2.00 px center drift). Mobile added a Reanimated UI-thread cull worklet (NativeMapViewport.tsx), localized <Svg viewBox>, >= 200-row outline virtualization, and MATH_CACHE_LIMIT = 2048.

Zoomed into a 30914 × 65438 canvas, it is still easy to lose your bearings. In v0.7.4, packages/layout/src/minimap.ts added isLargeMindmap (>= 40 nodes, or >= 18 spanning 2200 × 1600), clamped viewport lenses (>= 20 × 16), and iterative branch region grouping. Web/desktop pairs a <canvas> base layer with frame-synced ramilo-viewport-frame updates; React Native batches all edges and 6 branch color slots into <= 12 <Path> primitives driven by Reanimated CameraSharedValues, alongside opening iOS TestFlight (0.7.4 Build 26) directly from /download/.

✦

Comments

  • Loading…

Comments are reviewed before publishing; email is visible only to me.