Skip to content

[Improvement] Fix performance concerns — memory, N+1 queries, unbounded caches #195

@d-oit

Description

@d-oit

Description

Several performance concerns could impact users with large knowledge bases:

Memory Issues

Location Issue
App.tsx refreshData Calls getAllEntities() + getAllLinks() — loads everything into memory with no pagination
Editor.tsx repository.getAllEntities().then(setAllEntities) for mention menu — no virtualization
search.ts initSearch Bulk-loads ALL entities and claims into Orama index on init — no incremental hydration
search.ts oramaIdMap In-memory Map grows unbounded — no eviction
@huggingface/transformers ~80MB model download for embeddings, loaded eagerly

N+1 Queries

Location Issue
ExportPanel.tsx Sequential getClaimsByEntityId + getNotesByEntityId per entity — classic N+1

Unnecessary Re-renders

Location Issue
GraphView.tsx clearEdges() on every update, then re-adds all edges — should diff edges

Missing Debounce

Location Issue
Chat.tsx handleSend No debounce — rapid submissions could flood search

Recommended Fix

  1. Pagination: Add cursor-based pagination to getAllEntities() and getAllLinks()
  2. Virtualized mention menu: Use @tanstack/react-virtual for the entity mention dropdown
  3. Incremental search init: Load search index progressively, not all at once
  4. Cache eviction: Add LRU eviction to oramaIdMap with max size
  5. Batch queries: Add getAllClaimsWithNotes() to repository to avoid N+1
  6. Edge diffing: Diff graph edges instead of clearing and re-adding
  7. Lazy embeddings: Load @huggingface/transformers only when semantic search is enabled
  8. Debounce chat: Add 300ms debounce to Chat submit

Acceptance Criteria

  • refreshData supports pagination
  • Mention menu uses virtualization
  • Export uses batch queries instead of N+1
  • Graph edges are diffed, not cleared
  • oramaIdMap has max size with eviction
  • Chat has debounce on submit
  • @huggingface/transformers loaded lazily

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions