Running This Snippet Lags Out Studio (Plugin)

If you’re an existing StudioCLI user, you probably know that the package manager is extremely laggy when installing, uninstalling, and updating packages.

Here’s the important bit of code for installing a package (full source here):

-- packageName is either a number or a string
-- that eventually becomes a number

-----------------------------------------------

local packageName = regular[1]

if tonumber(packageName) then -- if it's a number ID
	--local latestVersion = SERVICES.InsertService:GetLatestAssetVersionAsync(tonumber(packageName))
	--local module = SERVICES.InsertService:LoadAssetVersion(latestVersion):GetChildren()[1]
	local objects = game:GetObjects("rbxassetid://"..tostring(packageName))
	local module = objects[1]
	if table.find(flags, "g") or args['global'] then
		if module then
			if not game.ReplicatedStorage:FindFirstChild("rbx_modules") then
				local rbx_modules = Instance.new("Folder", game.ReplicatedStorage)
				rbx_modules.Name = "rbx_modules"
			end
			module.Parent = game.ReplicatedStorage:FindFirstChild("rbx_modules")
			module:SetAttribute("rbx_package_ID", packageName)
		end
	elseif table.find(flags, "d") or args['dev'] then
		if module then
			module.Parent = self.UI.DEV_MODULES
			module:SetAttribute("rbx_package_ID", packageName)
		end
	else
		if module then
			module.Parent = self.PATH
			module:SetAttribute("rbx_package_ID", packageName)
		end
	end
	objects = nil -- Was this the memory leak?
else -- if its a string name that should become an ID
	if REGISTRY[tostring(packageName):upper()] then
		--local latestVersion = SERVICES.InsertService:GetLatestAssetVersionAsync(REGISTRY[tostring(packageName):upper()])
		--local module = SERVICES.InsertService:LoadAssetVersion(latestVersion):GetChildren()[1]
		local objects = game:GetObjects("rbxassetid://"..tostring(REGISTRY[tostring(packageName):upper()]))
		local module = objects[1]
		if table.find(flags, "g") or args['global'] then
			if module then
				if not game.ReplicatedStorage:FindFirstChild("rbx_modules") then
					local rbx_modules = Instance.new("Folder", game.ReplicatedStorage)
					rbx_modules.Name = "rbx_modules"
				end
				module.Parent = game.ReplicatedStorage:FindFirstChild("rbx_modules")
				module:SetAttribute("rbx_package_ID", packageName)
			end
		elseif table.find(flags, "d") or args['dev'] then
			if module then
				module.Parent = self.UI.DEV_MODULES
				module:SetAttribute("rbx_package_ID", packageName)
			end
		else
			if module then
				module.Parent = self.PATH
				module:SetAttribute("rbx_package_ID", packageName)
			end
		end
		objects = nil -- Was this the memory leak?
	end
end

I believe the culprit is game:GetObjects(), but still haven’t been able to figure it out.

Thoughts on how to fix this?

2 Likes

usually I would take out a part of the code such as that line, and see if it still lags

honestly looking at your code it seems like GetObjects() could be the cause, but

this link might help with this part(I say might because it doesn’t exactly have a solution on the post)

so I think it has to do with these two things imo

It’s more than just game:GetObjects(). I’ve narrowed it down to this:

local rbx_modules = game.ReplicatedStorage:FindFirstChild("rbx_modules")
if not rbx_modules then
    rbx_modules = Instance.new("Folder", game.ReplicatedStorage)
    rbx_modules.Name = "rbx_modules"
end
game.ServerStorage.ModuleScript:Clone().Parent = rbx_modules

If I remove the :Clone() from the last line, it’ll never lag. Otherwise, it continues to lag worse.

:Clone(), InsertService:LoadAsset, and game:GetObjects() are all causing this behavior. This is most definitely an internal issue.