UI Optimization

If anyone has made a game with lots of menus, do you bother disconnecting or destroying gui objects when not in use? or do you think that’s unnecessary? for example I could destroy and re-instance a list of product buttons in a shop menu on open/close, or just keep them instanced in the background.

1 Like

it depends, lets say you have something like an inventory system, and have a frame instance with item descriptions for every item you hover over, and 100+ items. In this case it can be inefficient.

Instancing new gui elements is most useful when you have menus within menus within menus, it also offers the benefit of not having to return gui to its initial state after animations, since you can just instance it from scratch.

This is the principle behind the popular UI framework named “React”, that Roblox ported to luau and basically made the entire coreguis and entire roblox client application with.
(also yes, this means the roblox app was entirely made with roblox GUI)

For very simple gui, visibility toggling is arguably better since creating new gui takes processing that using visibility doesn’t. But this becomes more debatable as UI gets bigger and more complicated since it becomes a choice between storing more instances in memory vs creating new instances and having the cpu compute them.

3 Likes

Disconnecting all connections and stopping GUI animations when the menu is not visible make sense, as it helps clean up memory and prevents resource usage on elements that aren’t visible.

Regarding the menus content, if you’re aiming for an ultra-optimized menu, I wouldn’t recommend destroying and recreating the content each time. Instead, you should store them in ReplicatedFirst or ReplicatedStorage and move them between storage and the menu container when opening or closing the menu, without destroying or cloning, just reparenting. This approach is much more performant, especially when you use a table to keep a track of the stored contents and their related parent, to avoid any FindFirstChild or other extra work process.

As for performances improvement, you might not see any difference if you’re using a decent device, however it does have a significant impact on low-end device, as storing gui in these storage avoid your device to unnecessarily render or consider them when interacting with others gui (it is same than huge map in workspace, as soon as you put it in storage, lags disappear).

2 Likes

Thank you I appreciate the insight. Do you know if theres any difference between reparenting and toggling visibility, or do they both stop rendering?

1 Like

Thank you, I guess it just comes down to use case. I didn’t know that about react either, I will definitely check it out

I’m not sure whether both do the same or are different, but toggling visibility should still have a positive impact on performance as well.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.