Skip to content

Conversation

@masaori335
Copy link
Contributor

A temporal buffer is needed in some cases. With this LocalBuffer, when the requested buffer size is smaller than the threshold (1024 in default), we can avoid allocating memory on the heap. Which brings us performance improvements.

@ywkaras pointed out this could be an alternative of Arena on
#6495 (comment)

Co-authored-by: Walt Karas wkaras@verizonmedia.com

@masaori335 masaori335 added this to the 10.0.0 milestone Mar 18, 2020
@masaori335 masaori335 self-assigned this Mar 18, 2020
limitations under the License.
*/

template <std::size_t EstSizeBound = 1024> class LocalBuffer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @ywkaras said, this 1024 comes from the default arena block size.

@masaori335 masaori335 force-pushed the local-buffer branch 3 times, most recently from 1fb143b to 4953523 Compare March 18, 2020 08:08
ywkaras
ywkaras previously approved these changes Mar 18, 2020
@ywkaras
Copy link
Contributor

ywkaras commented Mar 21, 2020

Is this redundant with #6536 ?

@masaori335
Copy link
Contributor Author

I'd like to keep these commits and PRs separated. #6536 is the first use case, but this could be used anywhere.

@masaori335 masaori335 requested a review from vmamidi April 6, 2020 23:34
@SolidWallOfCode
Copy link
Member

Seems a reasonable starting point. I have been working on something similar, but a bit more general.

The first is the MemArena class in libswoc++. That's not quite the same - it's based on the internal Arena class and is more useful for repeated temporaries.

The other is SplitVector<T,N> which would have the same API as std::vector but have a static part of N instances of T. LocalBuffer<4096> becomes SplitVector<char, 4096>. This can avoid some casting.

We might also consider bringing back the MemSpan class which is designed to help with passing back buffer descriptions.

Overall, though this seems a reasonable step at this point, since my other projects are still not ready for production.

@masaori335 masaori335 marked this pull request as draft April 10, 2020 02:00
A template class for temporally buffer. When requested buffer size is small, a buffer on stuck is used.

Co-authored-by: Walt Karas <wkaras@verizonmedia.com>
@masaori335 masaori335 marked this pull request as ready for review April 10, 2020 02:05
@masaori335
Copy link
Contributor Author

Pushed new commit address @SolidWallOfCode's comment. Also, I made the type of buffer generic.

@masaori335 masaori335 linked an issue Apr 10, 2020 that may be closed by this pull request
12 tasks
@randall
Copy link
Contributor

randall commented Apr 10, 2020

[approve ci autest]

@masaori335 masaori335 merged commit 2daf8c7 into apache:master Apr 12, 2020
@masaori335 masaori335 mentioned this pull request Apr 14, 2020
12 tasks
@masaori335 masaori335 removed a link to an issue Jul 2, 2020
12 tasks
@zwoop zwoop modified the milestones: 10.0.0, 9.1.0 Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants