-
Notifications
You must be signed in to change notification settings - Fork 138
Reduce buffer allocations #2320
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
Conversation
a506f2f to
3d8dee4
Compare
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
| //println(data.sizeInBytes) | ||
| // Only check small buffers | ||
| if (data.sizeInBytes < 1024) { | ||
| if (this.mem != null && this.mem!!.sizeInBytes == data.sizeInBytes && arrayequal(this.mem!!, 0, data, 0, data.sizeInBytes)) return this |
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.
Is this part deleted? I guess the point is not being marked as dirty, so it doesn't need to be uploaded to the GPU again.
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.
Pull Request Overview
This PR aims at reducing buffer allocations in the AGBuffer.upload methods by copying data directly when the buffer sizes match, instead of always cloning the buffer.
- Refactored overloaded upload functions for various data types to pass a needClone flag.
- Introduced a private upload method that conditionally copies or clones the buffer based on the existing memory size.
| upload(data, needClone = true) | ||
|
|
||
| private fun upload(data: Buffer, needClone: Boolean): AGBuffer { | ||
| if (mem?.sizeInBytes == data.sizeInBytes) { |
Copilot
AI
May 7, 2025
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.
[nitpick] Consider adding a check to compare the content of mem and data for small buffers, as the previous implementation did, to avoid unnecessary copying when the existing buffer already matches the new data.
|
Thanks! |
We can just copy data from buffer to buffer instead of making clone when buffers size match.