Skip to content

Memory & Performance Optimization for Multi-Tab System #302

Closed

Description

@malibio

Problem Statement

With multiple tabs/panes open, memory usage and performance can degrade. We need to:

  • Monitor and optimize memory consumption
  • Implement lazy loading of node data
  • Add cleanup when tabs close
  • Profile and optimize render performance

Current State

What Exists:

  • ✅ Multiple ReactiveNodeService instances
  • ✅ SharedNodeStore with subscriptions

What's Missing:

  • ❌ Memory profiling and monitoring
  • ❌ Lazy loading for inactive tabs
  • ❌ Cleanup logic for closed viewers
  • ❌ Performance budgets and alerts

Proposed Solution

Performance optimization strategy:

  1. Profile memory usage with dev tools
  2. Implement lazy loading for inactive tabs
  3. Add proper cleanup on viewer destruction
  4. Set performance budgets (target <100MB for 5 tabs)
  5. Optimize re-render paths

Key Areas

Memory Management:

  • Track memory usage per viewer
  • Implement cleanup for closed tabs (unsubscribe, clear caches)
  • Monitor for memory leaks

Lazy Loading:

  • Don't load node data for inactive tabs until viewed
  • Unload data for long-inactive tabs (configurable threshold)

Render Optimization:

  • Profile render performance
  • Minimize unnecessary re-renders
  • Optimize update propagation

Main Components Affected

Modified Files:

  • /packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts - Add cleanup
  • /packages/desktop-app/src/lib/services/shared-node-store.ts - Optimize subscriptions
  • /packages/desktop-app/src/lib/components/base-node-viewer.svelte - Lazy loading

Performance Targets

  • Tab switching: <50ms
  • Opening new tab: <100ms
  • Memory usage: <100MB for 5 tabs
  • No memory leaks over 100 tab open/close cycles

Acceptance Criteria

  • Memory profiling shows no leaks
  • Tab switching meets performance targets
  • Lazy loading reduces initial memory footprint
  • Cleanup properly unsubscribes and clears caches
  • Performance monitoring in place

Estimated Effort

4-6 hours

  • Memory profiling: 1 hour
  • Lazy loading implementation: 2 hours
  • Cleanup logic: 1 hour
  • Optimization and testing: 2 hours

Dependencies

Priority

Medium - Important for production quality but can be addressed after core features work

Activity

  1. malibio commented on Aug 3, 2026

    @malibio
    CollaboratorAuthor

    Dependency and status check — the premise still holds, with one claim unverified.

    All stated dependencies are closed: #206 (Tab/Pane Management), #297 (link navigation), #298 (tab controls), #300 (split-pane layout).

    Confirmed present, as the issue assumes:

    • Multi-tab / multi-pane system — lib/components/layout/tab-system.svelte, pane-manager.svelte, app-shell.svelte, lib/stores/layout.svelte.ts
    • Persistence — lib/services/tab-persistence-service.ts, layout-persistence-service.ts
    • SharedNodeStore with subscriptions — lib/services/shared-node-store.svelte.ts
    • Lazy loading does exist at the node component level — lib/design/components/node-component-loader.svelte.ts, schema-form-loader.svelte.ts
    • Per-tab expansion state persistence — lib/services/node-expansion-coordinator.ts:77-85,254

    Unverified: the issue asserts there is no cleanup logic on tab close (unsubscribe, clear caches). I did not trace the tab-close path, so that claim should be confirmed before any work starts — it may be partly handled. The "lazy loading for inactive tabs" gap is distinct from the node-level lazy loading above and does appear to be real.

    Note the file paths in the body are stale in one place: /packages/desktop-app/src/lib/components/base-node-viewer.svelte is actually at lib/design/components/base-node-viewer.svelte. The reactive-node-service.svelte.ts and shared-node-store paths are correct.

    Suggest the first step is profiling to confirm there is a real leak before implementing lazy-unload machinery.

  2. mstomar125 commented on Aug 3, 2026

    @mstomar125
    Contributor

    Parked for on-device (Mac) — this is frontend-visual, not backend-tractable headless

    Every axis of this issue needs the running desktop app + a profiler, which a headless backend environment can't provide:

    • Memory profiling / leak detection — measuring per-viewer memory and the <100 MB for 5 tabs budget requires the Tauri app's dev tools against real open tabs; there's nothing to measure headlessly.
    • Lazy loading + cleanup for closed/inactive tabs — the units are the Svelte frontend's ReactiveNodeService / SharedNodeStore lifecycle (subscribe/unsubscribe, cache clearing on viewer destruction). Correctness here ("did closing a tab actually release its memory / unsubscribe?") is only verifiable by running the app and watching the profiler, not by unit tests.
    • Render-path optimization — profiling and reducing re-renders is inherently a running-UI measurement task.

    Labeled frontend / performance, and it belongs to the desktop/frontend lane. Parking it here for the Mac.

    Suggested first cut when picked up on-device: instrument per-viewer memory (a dev-only overlay), then add deterministic cleanup on viewer destruction (unsubscribe from SharedNodeStore + clear the viewer's node cache) and confirm the release in the profiler before moving to lazy-load/unload thresholds. The backend already exposes what's needed (per-node fetch, subscriptions); the gap is entirely frontend lifecycle + measurement.

  3. self-assigned this
    on Sep 11, 2026
  4. mstomar125 commented on Sep 11, 2026

    @mstomar125
    Contributor

    Triage — closing as superseded by #2568

    Re-verified this from scratch against the current codebase (11 months since filing) rather than trusting the prose, including a real headless measurement.

    What actually exists today (vs. this issue's description):

    • ReactiveNodeService (packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts) is no longer a thing that holds its own node data per viewer. It's now a thin per-viewer UI-state adapter (expand/collapse, focus, depth) that delegates all node storage to a single global SharedNodeStore singleton (SharedNodeStore.getInstance()). Its destroy() method — the exact call every BaseNodeViewer makes on unmount — is an explicit documented no-op: "Node data reactivity now comes directly from SharedNodeStore's SvelteMap — there is no subscription to tear down."
    • SharedNodeStore is confirmed present as this issue assumed, with subscriptions (subscribe()/subscribeAll()), but it's a single app-wide singleton, not one per tab.
    • closeTab() (packages/desktop-app/src/lib/stores/navigation.svelte.ts:332) only cleans up scroll-position state and tab/pane bookkeeping — it never touches SharedNodeStore.
    • Lazy loading exists, but only at the component code level (node-component-loader.svelte.ts, schema-form-loader.svelte.ts lazy-load Svelte component bundles per node type). There is no lazy loading / unloading of node data by tab-active state — this part of the original proposal is still genuinely missing.
    • A real (not "baseline estimation") performance suite already exists at bun run test:perf / architecture-benchmarks.test.ts, but its one memory test is an explicit formula-based estimate and only exercises a single ReactiveNodeService — no multi-tab coverage existed before this triage.

    Real measurement (not just code-reading): wrote and ran a headless probe that opened 10 simulated tabs × 300 distinct nodes (3,000 total) into the real SharedNodeStore via createReactiveNodeService() + initializeNodes(), then called destroy() on all 10 (the same call every real tab-close triggers). Result: the shared store held 3,000 nodes before and after "closing" every tab — nothing was released. Heap grew ~16.5MB for those 3,000 plain node objects in the headless harness (no forced GC, so directional only, not a production number). This confirms the underlying concern is real, just shaped differently than originally described: it's not "N per-viewer duplicated caches," it's "one shared cache that only ever grows, with no eviction of documents no longer open anywhere."

    Decision: closing this as stale/superseded — the architecture it describes (per-viewer duplicated node data, needing per-viewer cleanup) no longer exists, and its proposed solution doesn't match the current single-shared-store shape. Filed #2568 with the accurate current architecture, the real measurement above, and a tight, currently-relevant acceptance-criteria list (real memory test using process.memoryUsage(), actual eviction tied to tab-close + an inactivity threshold, correctness for the existing multi-pane-same-node case, no eviction of nodes with pending writes). All of the original dependencies (#206, #297, #298, #300) remain closed, so #2568 is immediately pickable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions