-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Description
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
ILocalHistoryto 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
messageIndexhashmap internally for O(1) lookup times. - Improve dependency resolution complexity from
O(N × M)toO(N + M)
Notes
- Helps ensure SDS recovery and message processing remain efficient as history grows.
Metadata
Metadata
Assignees
Labels
No labels