-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
@Dimenpsyonal now can merge |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In beta testing do not merge