How efficient is GenerateGUID?

I am making a dropper system that will work as follows:

  • On the server, HTTPService’s GenerateGUID is called to create a random string.
  • This string will be stored in a dictionary; the monetary value of the block will also be stored in this dictionary
  • A RemoteEvent will be fired on the client of the owner of a tycoon.
  • On the client, this event will be used to create a block, which will have its name set to the randomly generated string, that only the owner of said tycoon can see.
  • This block will touch a part that will “clean it up” and fire a RemoteEvent to tell the server that the block has reached the end of the conveyer. Parameters for this event will be the block’s name, and Boolean attributes to see if the block passed through “upgraders.”
  • The server will check to see if the block’s name matches up to the one inside the table.
  • The server will then see if the block has been “upgraded” and apply those upgrades in respect to the original value
  • The server will then give the tycoon owner the money owed.

I think this system will be pretty secure from exploiters, but I’m worried what can happen when there are 20+ tycoons that could have upwards of 30+ droppers going each calling GUID often. Will it cause lag/performance issues? And if this is bad practice, what should be done instead?

its probably fast enough but you can also just test it for yourself to see if it lags

if its laggy then you could make a counter that counts up by 1 each time which would give a unique id

edit: if the counter goes too high then maybe its worse for performance so you can do counter %= 100000000 or some other number to put a limit on the size

if you want to save space or make it more unreadable you can encode/decode it to a higher base system with this module

local CustomNumbers = {}
CustomNumbers.__index = CustomNumbers

function CustomNumbers.new(alphabet)
	local Numbers = {}
	setmetatable(Numbers, CustomNumbers)
	Numbers.Alphabet = alphabet
	Numbers.AlphabetLength = #alphabet
	
	return Numbers
end

function CustomNumbers:Encode(x)
	local result = ""
	if x < 1 then return result end

	local quotient = x
	local remainder = -1
	
	while quotient ~= 0 do
		local dec = quotient - 1
		remainder = dec % self.AlphabetLength
		quotient = math.floor(dec / self.AlphabetLength)
		result = self.Alphabet[remainder + 1] .. result -- Compensated for lua's index 1 start
	end
	return result
end

function CustomNumbers:Decode(x)
	local sum = 0
	local index = 0

	for i = #x, 1, -1 do
		local c = x:sub(i,i)
		sum += table.find(self.Alphabet, c)*(self.AlphabetLength^index)
		index += 1
	end

	return sum
end

return CustomNumbers

using something like

ascii85 = {
		"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
		"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 
		"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", 
		"u", "v", "w", "x", "y", "z", 
		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", 
		"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", 
		"U", "V", "W", "X", "Y", "Z", 
		".", "-", ":", "+", "=", "^", "!", "/", "*", "?", 
		"&", "<", ">", "(", ")", "[", "]", "{", "}", "@", 
		"%", "$", "#"
	}

local encoder = CustomNumbers.new(ascii85)
local guid = encoder:Encode(12345) -- outputs something with less characters than 12345
1 Like

There’s gonna be no way to efficiently test it unless I have a lot of full servers to test with; obviously, that’s not gonna happen before I make the system.

I’ll check your script out

You’re unlikely to notice anything unless you’re generating thousands per second.

It is almost certainly C++ based so the overhead is extremely minimal, it’s not computationally expensive, so again there’s almost zero impact.

1 Like

There’s a chance there might be HUNDREDS generated per second, but it’s unlikely it will be any more than that.

Now, let’s say there are a lot of servers going at once, will the amount generated in one server affect others? I know if you fire DataStoreService too many times in one server it will absolutely affect the other servers

No, it won’t affect other servers.

I know the fact the function is on HttpService may make it seem like that, but the function doesn’t do any outside requests or run anything from outside the Roblox server

1 Like

You can use this script to try and benchmark it:

local http = game:GetService("HttpService")
local start_time = tick()
local amount = 20000

for i = 1, amount do
	http:GenerateGUID(false)
end

print(`Generated {amount} GUIDs in {tick() - start_time}`)

It took me 0.008s to generate 20,000, this proves the point it will be more than fine for your use case

2 Likes