Asking about clone performance

So I have two conditions,
First, clone both UI with one frame whenever needed.

Second, put empty UI in the beginning and clone the frame whenever needed.

Which is better for performance? Or is it the same?

1 Like

The second condition should be better for performance because with this condition, an empty UI is being instanced and then the frame that you need is cloned into it.
With the first condition, it may take longer to find the frame that’s needed depending on the number of objects in the UI - assuming you delete all the children of the UI using a loop

Overall, both conditions should be fine as long as you don’t have hundreds of objects in the UI

you could image the clone function working something like this

-- this function is not 100% correct Roblox will do more things like change the attachments to use the cloned attachments and properties like primerypart will be changed to be the cloned part
local function Clone(instance)
    if instance.Archivable == false then return end
    -- make a new instance with the same class name
    local clone = Instance.new(instance.ClassName)
    -- copy all the properties to the new instance
    for property, value in pairs(instance.Properties) do clone[property] = value end
    -- set parent to nil
    clone.Parent = nil

    -- loop all children
    for i, child in ipairs(instance:GetChildren()) do
        -- clone the child
        local childClone = Clone(child)
        -- if the child is not archivable then skip
        if childClone == nil then continue end
        -- set the childClones parent to the clone
        childClone.Parent = clone
    end

    -- return the clone
    return clone
end

if your creating and destroying 100s of UI’s over and over again it would be best to cache the UIs and reuse old UIs over and over this project is opensource and might help show you how to cache the UI’s PartCache, for all your quick part-creation needs