Fastest Lua script

Hello
I want to tell you this honestly
I used AI to build one of my plugin
And I came across something really cool by accident
I live in Iran, the economy is not good here, so people usually have weak computers
I have a hard drive that was sold to me new, but later I found out that it had been working for 10 years
And I have a stock i7-3770 CPU
And the interesting thing was that it analyzes each line of code with about 100 programming rules and tells me about about 4 thousand scripts in less than 1.5 seconds
That is, it prepares a list of all the problems and sends it to the UI
And the thing is that it is very fast
Do you think this is an innovation? What if I make a YouTube video?
local RunService = game:GetService(“RunService”)

local ScriptAnalyzer = {}

-- پارامترهای دینامیک برای مدیریت بودجه زمانی (بر حسب ثانیه)
local BASE_BUDGET = 0.012  -- شروع با 12ms
local MAX_BUDGET  = 0.05   -- حداکثر 50ms
local MIN_BUDGET  = 0.005  -- حداقل 5ms
local BUDGET_STEP = 0.002  -- گام تنظیم خودکار

-- اطمینان از وجود جدول قوانین
assert(rules, "ScriptAnalyzer: rules table is not defined")

-- آماده‌سازی matcherها بر اساس الگو یا تابع
for _, rule in ipairs(rules) do
	if type(rule.pattern) == "string" then
		local pat = rule.pattern
		rule._matcher = function(line)
			return string.find(line, pat)
		end
	elseif type(rule.test) == "function" then
		rule._matcher = rule.test
	else
		error("Invalid rule: must have .pattern (string) or .test (function)")
	end
end

-- تابع کمکی: بررسی همه‌ی قوانین روی یک خط
local function matchAll(line)
	local matches = {}
	for _, rule in ipairs(rules) do
		local success, match = pcall(rule._matcher, line)
		if success and match then
			table.insert(matches, rule.message)
		end
	end
	return matches
end

function ScriptAnalyzer.AnalyzeAsync(callback, targets)
	assert(type(callback) == "function", "AnalyzeAsync: callback must be a function")

	local sourceList = (type(targets) == "table" and #targets > 0) and targets or game:GetDescendants()
	local scripts = {}
	for _, obj in ipairs(sourceList) do
		if obj:IsA("Script") or obj:IsA("LocalScript") or obj:IsA("ModuleScript") then
			table.insert(scripts, obj)
		end
	end

	local total = #scripts
	if total == 0 then
		task.defer(function() callback({}, 1) end)
		return
	end

	local results = {}
	local scriptIndex = 1
	local currentScript, lines, lineIndex
	local timeBudget = BASE_BUDGET

	local conn
	conn = RunService.Heartbeat:Connect(function()
		local frameStart = os.clock()

		while (os.clock() - frameStart) < timeBudget do
			if not currentScript then
				if scriptIndex > total then
					conn:Disconnect()
					task.defer(function() callback(results, 1) end)
					return
				end
				currentScript = scripts[scriptIndex]
				scriptIndex = scriptIndex + 1

				local ok, src = pcall(function() return currentScript.Source end)
				if ok and type(src) == "string" then
					lines = string.split(src, "\n")
					lineIndex = 1
				else
					warn(('[Analyzer] Couldn\'t read source of %s'):format(currentScript:GetFullName()))
					table.insert(results, { message = "Failed to read source", line = 0, script = currentScript })
					currentScript = nil
				end
			end

			if currentScript and lines then
				while lineIndex <= #lines do
					local ln = lineIndex
					local line = lines[ln]
					lineIndex = lineIndex + 1

					-- نادیده گرفتن خطوط کامنت‌شده
					if not line:match("^%s*%-%-") then
						local msgs = matchAll(line)
						for _, msg in ipairs(msgs) do
							-- اضافه کردن شماره خط و خود محتویات خط به پیام
							table.insert(results, {
								message = ("line %d: %s\n>> %s"):format(ln, msg, line),
								line    = ln,
								script  = currentScript,
							})
						end
					end

					if (os.clock() - frameStart) >= timeBudget then
						return
					end
				end

				currentScript, lines, lineIndex = nil, nil, nil
				local prog = math.clamp((scriptIndex - 1) / total, 0, 1)
				task.defer(function() callback(results, prog) end)
			end
		end

		local used = os.clock() - frameStart
		if used < timeBudget * 0.5 and timeBudget < MAX_BUDGET then
			timeBudget = math.min(timeBudget + BUDGET_STEP, MAX_BUDGET)
		elseif used > timeBudget * 0.9 and timeBudget > MIN_BUDGET then
			timeBudget = math.max(timeBudget - BUDGET_STEP, MIN_BUDGET)
		end
	end)
end

function ScriptAnalyzer.Analyze()
	local done, output = false, {}
	ScriptAnalyzer.AnalyzeAsync(function(res, prog)
		output = res
		if prog >= 1 then done = true end
	end)
	repeat task.wait() until done
	return output
end

return ScriptAnalyzer

If you don’t understand what I’m saying, check out this plugin.

2 Likes

9 Likes

Are you kidding or for real?

I really liked the explanation you gave about yourself.

This is nothing revolutionary. Computers really are just fast. Even the very old ones. Arguably the most insane and amazing invention of all time.

1 Like

Of course, in a way, it’s good that it detects how much speed should be used to prevent a crash.

the concept of using an ai made script to check probably other ai made scripts from free models

1 Like

I don’t understand, please be more specific.

the people who are most likely to use this are people who cant script at all, which defeats the purpose

and ai bad

2 Likes

lol, i like ur bio too, but @amindez24 this ain’t revolutionary, this is how fast computers are, and i am sorry for you, i hope life gets better for u :folded_hands::slightly_smiling_face:

1 Like

Thank you brother, people like you are rare. I always wanted to have friends like you.
I’m glad someone understood this life.

1 Like