-
Notifications
You must be signed in to change notification settings - Fork 48
chore(sds): optimise lookups #2745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/persistent_history
Are you sure you want to change the base?
Conversation
…istentHistory` to use composition over inheritance for history management.
…e key generation.
…ifying history storage initialization to default to `localStorage`
…mproved compatibility.
…in message channels
…d refactor `MemLocalHistory` to support optional persistent storage.
…ingDependencies`
size-limit report 📦
|
|
This PR should go before the persistent storage one. Because here, you are refining the interface to implement, and in persistent storage, you are adding a second implementation. |
| * If an array of items longer than `maxLength` is pushed, dropping will happen | ||
| * at next push. | ||
| */ | ||
| export interface ILocalHistory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MessageChannel is the one to define the interface, hence this should be in message_channel.ts.
| addMessages(...messages: ContentMessage[]): void; | ||
| hasMessage(messageId: string): boolean; | ||
| getMessage(messageId: string): ContentMessage | undefined; | ||
| getRecentMessages(count: number): ContentMessage[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the expectation is for this to be ordered? if so, I'd add it to the name.
| } | ||
|
|
||
| public get length(): number { | ||
| public get size(): number { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
| private items: ContentMessage[] = []; | ||
| private messageIndex: Map<string, ContentMessage> = new Map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private items: ContentMessage[] = []; | |
| private messageIndex: Map<string, ContentMessage> = new Map(); | |
| private orderedMessageArray: ContentMessage[] = []; | |
| private messageMap: Map<string, ContentMessage> = new Map(); |
I don't think a Map qualify as an index because it cotnains both keys (index) and values (not a ref)
| // Remove duplicates by messageId while maintaining order | ||
| this.items = _.uniqBy(combinedItems, "messageId"); | ||
|
|
||
| this.rebuildIndex(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are rebuilding the index, and then you are removing items from the array, and then you are removing the removed items from the index.
I think there is a better way to do this.
75e8e12 to
e396c3b
Compare
Problem / Description
ILocalHistorywas designed as an array-like interface (push,find,some,slice) which requiredO(N × M)array scans for dependency checking, which resulted in expensive lookup timesSolution
ILocalHistoryto implement a domain-specific interface:messageIndex) behindILocalHistoryforO(1)lookups for missing dependencyO(N+M)Notes
Checklist