Blazingly Fast String Compression (ZSTD)

FYI - Roblox implicitly compresses buffers using ZSTD behind the scenes when you send them over the wire (remotes, http service, etc.), or at rest (data stores, memory stores). No Luau implementation is going to beat the natively compiled ZSTD operation.

So you can do:

local myStr = "Pretend this is a much longer string..."
local buf = buffer.fromstring(myStr)

-- Examples:

-- "buf" is compressed over the network automatically:
remote:FireAllClients(buf)

-- "buf" is decompressed automatically:
remote.OnServerEvent:Connect(function(buf)
end)

-- "buf" will be compressed in the datastore:
dataStore:SetAsync("key", buf)

-- "buf" will be automatically decompressed:
buf = dataStore:GetAsync("key")

Note: Roblox might compress it, but not always. It uses whatever is best. For small data, often the uncompressed data is smaller.

3 Likes