-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Recycle buffer lines #1731
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
Recycle buffer lines #1731
Conversation
ceb955b to
33a3580
Compare
|
@Tyriar Here comes the new approach: a callback version of push. It was the fastest thing I could come up with. I first tried your trim idea with another method, but it was much worse in runtime. Still up for other ideas. NB: I kinda screwed up the branch and had to reset it lol. |
|
Added an For my typical benchmark
With that small change in Edit: The numbers above are the total JS runtime for my benchmark which also contains the renderer runtime and the websocket overhead (unbuffered in the server script). Currently I have no isolated input only test setup, but we can approximate the boost by subtracting these numbers:
Final speedup for the input handler code average:
Speedup master vs. recycled TypedArray: 1100 vs. 900 => ~18% Guess I should do a real input chain benchmark to get more reliable numbers. |
|
Here are the numbers for the input chain alone (done with this script https://gist.github.com/jerch/31f23538c5ca1a5079a78bbd627398ce, ./benchmark_data1 contains the output of Seems the typed array + recycling doubles the throughput 😄 Question here is what to make out of these numbers and why they differ that much from the numbers in the browser:
Perfwise I think the numbers from the nodejs tests are closer to the truth - they only measure the input chain thats affected most by the changes while the browser tests seem to measure some side effects as well. |
|
@Tyriar Did a version without the callback as you suggested (see last commit). Well, seems it has several flaws:
I dont like the callback thing either here, its just I had no better idea, how to put it without exposing to many internals. Still up for other ideas. Edit: Woops forgot to push, see commit below. |
|
@Tyriar Removed the callback variant, Now it works as follows for recycling:
The blueprint is needed to have something to copy the cell content from without recreating a line everytime. The blueprint alone already gives a nice speedup since the cached blankline is unlikely to change very often.
Up for another review. |
Tyriar
left a comment
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 pretty solid, just a few things and I think we can merge this!
|
@Tyriar Something like this should work: public pushFromBlueprint(blueprint: IBufferLine, allowRecycle?: boolean): void {
if (this._length === this._maxLength) {
this._startIndex = ++this._startIndex % this._maxLength;
this.emit('trim', 1);
if (allowRecycle) {
(this._array[this._getCyclicIndex(this._length - 1)] as unknown as IBufferLine).copyFrom(blueprint);
} else {
this._array[this._getCyclicIndex(this._length - 1)] = blueprint.clone() as unknown as T;
}
} else {
this._array[this._getCyclicIndex(this._length)] = blueprint.clone() as unknown as T;
this._length++;
}
}But this has several issues:
Note it is not possible to give |
|
@Tyriar The last commit reverts to a cleaner precheck version and does the recycling explicitly in |
|
@Tyriar The last commit is a compromise between speed and code safety. Was not able to remove the double checking of |
9ee0b51 to
895d6fc
Compare
|
Averages now to ~18.5 MB/s, this is a nice enhancement compared to ~7.5 MB/s in the current master. |
Tyriar
left a comment
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.
🎉
A first attempt to recycle buffer lines.
Can be tested by switching
experimentalBufferLineImpltoTypedArray.Note: The recycling is only active for the typed array version to make it a fair comparison (the JS array version is much slower with it). Still buggy with faulty behavior in some tests (cannot be tested easily atm, the tests currently rely on the hardcoded JS array type). More to come...The recycling is now active for both buffer line versions.
Part of #791