Performance Problems When Adding Buffers Together in Roblox

I’m working on a script that involves combining two buffers buffer1 and buffer2. Specifically, I’m trying to add the values from buffer2 into buffer1. Here’s the simplified version of my code:

for Index = 0, BufferSize * 4 - 1 do
    local Value = buffer.readu8(buffer2, Index)
    buffer.writeu8(buffer1, ColorIndex, Value)
    ColorIndex += 1
end

The problem is that this approach is extremely slow, especially when the buffers are large. The readu8`and writeu8 operations seem to be the problem , they are called in each iteration of the loop.

I’m looking for advice on potential strategies to speed it up…

for Index = 0, BufferSize * 4 - 1 do
local Value = buffer.readu8(buffer2, Index)
buffer.writeu8(buffer1, ColorIndex, Value)
ColorIndex += 1
end

There’s already a built in function to copy over data from one buffer to another.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.