Skip to content

[P1/arch] Every addEntry writes the entire entries array to localStorage synchronously — no debounce #331

Closed

Description

@EVWorth

Context

historyStore.ts uses zustand/middleware::persist (src/stores/historyStore.ts:30-38) which writes the entire JSON state on every set.

Problem

With MAX_ENTRIES = 500 and an average entry of ~500 bytes (SQL + connection name + timestamps), each addEntry triggers a synchronous localStorage write of ~250 KB. That's measurable on slow disks (HDD, encrypted APFS) and blocks the main thread. The DebounceEditor (editorStore.ts:351-365) handles this with a 500ms debounce — the history store doesn't. After F1 raises the cap, the cost grows linearly.

Files

  • src/stores/historyStore.ts:30-38

Expected

In-memory state is immediately reactive (UI updates synchronous), but the localStorage write happens on a 500ms idle window.

Proposed fix

Scope S — wrap the set from addEntry in a debounced setter (Mirror editorStore.ts:351-365 pattern: _saveTimeout set/clear).

Acceptance

Rapid-fire 100 queries within 2 seconds result in ≤ 2 localStorage writes (instead of 100); the in-memory state is still up-to-date immediately.

Needs human verify

no

Activity

  1. added
    audit
    severity/p1
    kind/arch
    area/history
    on Jul 31, 2026
  2. EVWorth commented on Sep 9, 2026

    @EVWorth
    OwnerAuthor

    Superseded by #585. The full-array synchronous rewrite is a property of persisting to localStorage, not something to debounce around — moving history to SQLite removes the problem rather than softening it. Closing in favour of that unless there's a reason to keep it separate.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/historyauditkind/archseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions