buffer.resize pros and cons #1304
Replies: 3 comments 5 replies
-
We went over resizable buffers in the initial RFC already. |
Beta Was this translation helpful? Give feedback.
-
1Gb size limitation follows the current string size limitation. |
Beta Was this translation helpful? Give feedback.
-
You can think of a buffer like a memory allocation in C++. |
Beta Was this translation helpful? Give feedback.
-
I've been thinking about pros and cons of
buffer.resize
lately. Here are my thoughts in case they are useful. This could be extended to a RFC if the developers of Luau want to go in this direction.Motivation:
buffer.resize(buf, 0)
Performance considerations:
Performance difference for buffer accesses would be likely negligible for buffers larger than 56 bytes (= 64 - header) because both versions need to access 2 cache lines (assuming 64 byte cache lines). For very small buffers though the current implementation only needs to access one cache line. Assumption is that such very small buffers are rare, so in practice I doubt the performance difference matters. A benchmark could be written to examine this more closely.
With resizable buffers, creating a new buffer would need 2 memory allocations, so creating and freeing a buffer will likely be somewhat slower. This is the only practical downside I can see.
Other:
len
inBuffer
could be changed fromint
tosize_t
without downsides (since GC object needs to be at least 16 bytes).Beta Was this translation helpful? Give feedback.
All reactions