Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use buffer for deserialisation instead of string #1478

Merged
merged 5 commits into from
Apr 27, 2024

Conversation

ccuser44
Copy link
Contributor

In beta testing do not merge

@Dimenpsyonal Dimenpsyonal added ✨ enhancement Enhancing or improving existing functionality ⌛needs PoF This PR is awaiting proof of functionality labels Apr 26, 2024
@ccuser44
Copy link
Contributor Author

PoF:
image
image

Speedtest:
image
Script:

local HttpService = game:GetService("HttpService")
local ls, fiOne1, fiOne2 = require(script.Loadstring), require(script.FiOne1), require(script.FiOne2)

local ITERATIONS = 2^15*15
local TEMPLATE = [[
local %s = "%s"

local function %s(%s)
	return %s, %s
end

for %s, %s in {%s} do
	print(%s, %s, %s, %s(%s))
end
]]
local CHARS_START = {
	"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 CHARS = {
	"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 BLACKLISTED_WORDS = {
	["and"] = true , ["break"] = true , ["do"] = true , ["else"] = true , ["elseif"] = true , ["end"] = true , ["false"] = true , ["for"] = true , ["function"] = true , ["goto"] = true , ["if"] = true , ["in"] = true , ["local"] = true , ["nil"] = true , ["not"] = true , ["or"] = true , ["repeat"] = true , ["return"] = true , ["then"] = true , ["true"] = true , ["until"] = true , ["while"] = true , ["continue"] = true
}

local bytecode = table.create(ITERATIONS)
local t1, t2 = 0, 0
local deserialise1, deserialise2 = fiOne1.bc_to_state, fiOne2.bc_to_state

local function makeRandomVar()
	local lenght = math.random(3, 6)
	local var = table.create(lenght)
	var[1] = CHARS_START[math.random(1, 53)]

	for i = 2, lenght do
		var[i] = CHARS[math.random(1, 63)]
	end

	local v = table.concat(var)
	
	if not BLACKLISTED_WORDS[v] then
		return v
	else
		return makeRandomVar()
	end
end

local function makeRandomConstList()
	local lenght = math.random(3, 9)
	local consts = table.create(lenght * 3 + 1)

	for i = 1, lenght do
		consts[(i - 1) * 2 + 1] = tostring(math.random(1, 50))
		consts[(i - 1) * 2 + 2] = ", "
	end

	consts[lenght * 2 + 1] = tostring(math.random(1, 50))

	return table.concat(consts)
end

for i = 1, ITERATIONS do
	local varname, fname, argname, iname, vname = makeRandomVar(), makeRandomVar(), makeRandomVar(), makeRandomVar(), makeRandomVar()
	local var = select(2, ls(string.format(
		TEMPLATE,
		varname, HttpService:GenerateGUID(),
		fname, argname,
		argname, makeRandomConstList(),
		iname, vname, makeRandomConstList(),
		iname, vname, makeRandomConstList(), fname, makeRandomConstList()
		), "LuaC"))

	if type(var) ~= "string" then
		error("INVALID!!")
	else
		bytecode[i] = var
	end

	if i % (2^11) == 0 then
		task.wait()
	end
end

task.wait(2)
print("Compiled. Starting to serialise")
task.wait(2)

local dummyCounter = 0 -- Trick Luau compiler in to disabling optimisations

for i = 1, ITERATIONS do
	local start = os.clock()
	local bytecode1, bytecode2
	
	if i % 2 == 0 then
		bytecode2 = deserialise2(bytecode[i])
	else
		bytecode1 = deserialise1(bytecode[i])
	end

	local e = os.clock() - start
	dummyCounter += #(bytecode1 or bytecode2)

	if i % 2 == 0 then
		t2 += e
	else
		t1 += e
	end

	if i % (2^13) == 0 then
		task.wait()
	end
end

print(dummyCounter, "\n", string.format("NoBuffer: %d\nBuffered: %d", t1, t2))

@ccuser44 ccuser44 marked this pull request as ready for review April 27, 2024 12:42
@Dimenpsyonal Dimenpsyonal removed the ⌛needs PoF This PR is awaiting proof of functionality label Apr 27, 2024
@ccuser44
Copy link
Contributor Author

@Dimenpsyonal now can merge

@Dimenpsyonal Dimenpsyonal merged commit ad19c49 into Epix-Incorporated:master Apr 27, 2024
2 checks passed
@ccuser44 ccuser44 deleted the patch-9 branch April 27, 2024 13:16
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
✨ enhancement Enhancing or improving existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants