-
Notifications
You must be signed in to change notification settings - Fork 79
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
perf: faster addMessagesSorted #470
Conversation
Size Change: +254 B (0%) Total Size: 197 kB
|
let middle = 0; | ||
let right = messages.length - 1; | ||
while (left <= right) { | ||
middle = Math.floor((right + left) / 2); |
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.
In most cases wouldn't a bottom up approach be faster than a binary search given the likelihood of a message being further up is less?
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.
L462 takes care of that. cases like pagination could add some 100 more messages to the other end of the array which will be O(n), right now this part is O(log(n)) which is quite fast already
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.
Looks good lets test
…chat-js into perf-addMessagesSorted
@@ -1658,7 +1658,7 @@ export class Channel< | |||
if (!this.state.messages) { | |||
this.state.messages = Immutable([]); | |||
} | |||
this.state.addMessagesSorted(messages, true); | |||
this.state.addMessagesSorted(messages, false, true); |
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.
Having options an object with keys would help for readability.
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.
3 params are fine, in case it grows we can change it to object
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 agree in general but when they are booleans, it's trickier.
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.
💯 LGTM
fixes #465