How do I optimize a scrolling frame for over 1000 frames?

Ok so I wanted to come back to this thing. The adding of info frames and placement of everything works nicely. Problem is that its still lagging. Getting around 50 fps.

local List = {}
local ReplicatedStorage = game.ReplicatedStorage
local UIGridLayout = script.Parent.Nest.UIGridLayout
local HTTPSService = game:GetService("HttpService")
local ScrollingFrame = script.Parent
local Nest = script.Parent.Nest
local NewlyVisibleFrames = {}

local PreviouslyVisible = {}
--- ... later in the script...
function UpdateNest()
	Nest.Size = UDim2.new(Nest.Size.X.Scale, 0, 0, UIGridLayout.AbsoluteContentSize.Y)
end

function UpdateCanvasSize()
	ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, UIGridLayout.AbsoluteContentSize.Y)
end
function update_visible_frames(AmmountInTable)
	local CellPaddingY = UIGridLayout.CellPadding.Y.Offset
	local TopCanvasPosition = Nest.AbsolutePosition.Y
	local TopWindowPosition = ScrollingFrame.AbsolutePosition.Y
	local TopOfficialSize = (TopWindowPosition-TopCanvasPosition)
	local FrameYTop = math.floor((TopOfficialSize/(UIGridLayout.AbsoluteCellSize.Y+UIGridLayout.CellPadding.Y.Offset))*UIGridLayout.AbsoluteCellCount.X + .5)
	local AmmountInWindow = math.floor((ScrollingFrame.AbsoluteSize.Y/(UIGridLayout.AbsoluteCellSize.Y+UIGridLayout.CellPadding.Y.Offset))*UIGridLayout.AbsoluteCellCount.X + .5)
	FrameYTop = math.clamp(FrameYTop-UIGridLayout.AbsoluteCellCount.X, 0, 2e9)
	local FrameYBottom = (FrameYTop + AmmountInWindow)+(UIGridLayout.AbsoluteCellCount.X*2)
	if FrameYBottom > AmmountInTable then
		FrameYBottom = AmmountInTable
	end
	PreviouslyVisible = NewlyVisibleFrames
	NewlyVisibleFrames = {}
	for i = FrameYTop, FrameYBottom do
		if List[i] then
			local Frame = List[i]
			local find = table.find(PreviouslyVisible, Frame)
			if find then
				table.remove(PreviouslyVisible, find)
			end
			if not Frame:FindFirstChildOfClass("Folder") then
				ReplicatedStorage.Info:Clone().Parent = Frame
			end
			table.insert(NewlyVisibleFrames, Frame)
			--print(Frame)
			--print(NewlyVisibleFrames)
		end
	end
	for i, v in pairs(PreviouslyVisible) do
		if v:FindFirstChildOfClass("Folder") then
			v.Info:Destroy()
			
		end
	end
end
local Entrys = 10000
for i = 1, Entrys do
	local clone = script.Template:Clone()
	clone.Name = HTTPSService:GenerateGUID(false)
	clone.Parent = ScrollingFrame.Nest
	table.insert(List, clone)

	--if i % (math.ceil(Entrys*1)) == 0 or i == 1 then
	--PilesOfLists[#PilesOfLists+1] = {}
	--end

	--table.insert(PilesOfLists, HttpService:GenerateGUID(false))
end
function UpdateAll()

	--UpdateScrollingFrame()

	UpdateNest()

	UpdateCanvasSize()

	update_visible_frames(#List)

end

UpdateAll()

ScrollingFrame:GetPropertyChangedSignal("CanvasPosition"):Connect(function()

	update_visible_frames(#List)

end)

ScrollingFrame:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()

	UpdateAll()

	--UpdateNest()

	--UpdateScrollingFrame()

	--update_visible_frames(#List)

	--UpdateUIGridLayout()

end)

How many entry’s did you add? If you really did add 10,000 then of course you will be getting fps drops. Like the max I would stay with is around 4 - 5k

But I am confused what the code is even doing. It doesn’t say anywhere

.Parent = nil 
.Visible = false

Doesn’t say anything. It just adds an info frame to frames player can see.

The idea is to add and remove info frames when they are in or out of view. So this will eliminate a lot of positioning caused by a scrolling frame which causes the fps to drop.

1 Like

Need help on this, this is my current set up

There’s a frame → scrolling frame → imagelabel (the actual object i want to display / turn off if not in view)

How can I adapt the code to work with my set up?

1 Like