What's the Optimal Way to Get Hashkeys?

Well, I just tested this using the following code:

function SpawnVehicle(model)
	RequestModel(model)
	while (not HasModelLoaded(model)) do
		Wait(0)
	end
	local veh = CreateVehicle(model, GetEntityCoords(PlayerPedId()), 0.0, true, true)
end

RegisterCommand("v1", function(src, args, raw)
	SpawnVehicle(joaat(args[1]))
end, false)

RegisterCommand("v2", function(src, args, raw)
	SpawnVehicle(args[1])
end, false)

And both of the work on a 5848 server and current beta client build.

Also done some testing regarding performance using the following code:

RegisterCommand("perf", function(src, args, raw)
	local model = "adder"
	Wait(0)
	for i = 1, 100000 do
		RequestModel(model)
		HasModelLoaded(model)
	end
	Wait(0)
	print("string:", GetFrameTime())

	model = `adder`
	Wait(0)
	for i = 1, 100000 do
		RequestModel(model)
		HasModelLoaded(model)
	end
	Wait(0)
	print("hash:", GetFrameTime())
end, false)

image

Using the string version seems to be slower at 60% of the hash version. But it barely makes any sort of difference if you call it only once. I also tried it with “just a thousand times” and they are basically the same.

Tested on a beefy system (Ryzen 7 5800x, Zotac GTX 1080 Amp Extreme, ~100-180fps) and the worst client side resources were the default chat and the spawnmanager xD

1 Like