Skip to content

chore(sds): optimise lookups #2755

@danisharora099

Description

@danisharora099

Description

The current ILocalHistory implementation behaves like an array (push, find, some, slice), which forces repeated linear scans when checking message dependencies. This results in an O(N × M) complexity for dependency resolution and causes performance degradation as history size grows.

While the behavior is functionally correct, the architecture is inefficient for large or frequently accessed histories. A domain-specific API is needed to support efficient lookups and scalable dependency checks.


User Story

  • As a developer, I want ILocalHistory to support efficient message lookups and dependency checks, so that SDS can perform reliably at scale without incurring unnecessary computation.
  • As a system integrator, I want predictable and performant history operations, so growing message histories do not negatively impact runtime.

Proposed Solution / Feature Design

Refactor ILocalHistory to use a domain-specific interface backed by a hashmap that enables O(1) message lookups.

New Interface

export interface ILocalHistory {
  readonly size: number;
  addMessages(...messages: ContentMessage[]): void;
  hasMessage(messageId: string): boolean;
  getMessage(messageId: string): ContentMessage | undefined;
  getRecentMessages(count: number): ContentMessage[];
  getAllMessages(): ContentMessage[];
  findMissingDependencies(entries: HistoryEntry[]): HistoryEntry[];
}

Key Design Changes

  • Remove generic array-like behaviors (push, find, some, slice).
  • Introduce clear, purpose-built history methods.
  • Use a messageIndex hashmap internally for O(1) lookup times.
  • Improve dependency resolution complexity from O(N × M) to O(N + M)

Notes

  • Helps ensure SDS recovery and message processing remain efficient as history grows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions