Hello! When I found out about string concatenation’s absurdly poor performance in loops (I estimated concatenation is about 555 times slower) I decided to make this library which makes the process of permanently concatenating a lot of things at once much simpler.
You can find the source code here: StringBuilder - Replit (Only 26 lines of code!) This allows you to seamlessly and permanently concatenate strings within a loop without really changing your code too much. You should keep in mind that the table version has slightly better performance and it has a better memory footprint so you’re better off using that in your projects.
Here are some examples of how you can use this:
local builder = StringBuilder.new("example", "123") -- Creates a string builder with "example 123" as it's text
builder = builder.."456" -- Directly concatenates the given items just like a string. Note that this changes the builder object itself, and does not return a new object!
builder = builder + "abc" + "def" -- Concatenates the given items to the builder separated by spaces. This also changes the actual builder object like above.
builder = tostring(builder) -- Converts the builder to a string. This is also done by print, but this allows you to get its string value.
print(builder) -- Prints "example 123456 abc def"
builder = builder("Stuff!", builder) -- Returns a new StringBuilder generated with the given arguments. Note: This only accepts strings as arguments!
Additionally, this post describes the performance issues I’ve come across, and has a bit of discussion on the topic: https://devforum.roblox.com/t/psa-string-concatenation-is-really-slow-use-table-concat/475583
