Skip to content

Performance: Unbounded event-log growth — persist file and MemoryStore.events never compacted during operation #59

Description

@jonbaldie

Finding — Asymptotic space complexity: O(E), unbounded

Subsystem: Persist — FileStore (src/persist.ts:22–37), MemoryStore (src/persist.ts:96–103), Manager (src/manager.ts:72,99)

Input variable

E = total enqueue+dequeue operations over process lifetime

Current complexity

  • Space: O(E), unbounded — never compacted during operation

Cause

Every enqueue() and dequeue() unconditionally calls this.store.saveEvent(...) (src/manager.ts:72,99), regardless of whether persistence is enabled.

  • FileStore: saveEvent appends to persist.dat without compaction. The file grows with every operation until the process restarts. Only save() at shutdown or load() at startup compact it.
  • MemoryStore (persistence disabled, i.e. --persist flag absent): saveEvent pushes to an in-memory events[] array that is never read and never cleared — a pure memory leak with no benefit.

main.ts:15–17 selects MemoryStore when persistEnabled is false; manager.ts:72,99 calls saveEvent unconditionally; neither MemoryStore.events nor persist.dat is compacted during operation.

Remediation direction

  • For MemoryStore with persistence disabled: make saveEvent a no-op.
  • For FileStore: periodic snapshot compaction (clear + rewrite current state) or write-ahead log with checkpoints.

Confidence

High — source analysis. No long-running runtime measurement; impact scales with uptime and traffic volume.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions