Unity UI (UGUI) can often be a source of performance issues. The Canvas component generates and updates meshes for the UI elements and issues draw calls to the GPU. Its functioning can be expensive, so keep the following factors in mind when working with UGUI.
If you have one large Canvas with thousands of elements, updating a single UI element forces the whole Canvas to update, which can potentially generate a CPU spike.
Take advantage of UGUI’s ability to support multiple Canvases. Divide UI elements based on how frequently they need to be refreshed.
Keep static UI elements on a separate Canvas, and dynamic elements that update at the same time on smaller sub-canvases.
Isolate big dynamic elements in their own canvas (es. scroll rect)
Ensure that all UI elements within each Canvas have the same Z value, materials, and textures.
You might have UI elements that only appear sporadically in the game (e.g., a health bar that appears when a character takes damage). If your invisible UI element is active, it might still be using draw calls. Explicitly disable any invisible UI components and re-enable them as needed.
If you only need to turn off the Canvas’s visibility, disable the Canvas component rather than GameObject. This can save rebuilding meshes and vertices.
se va nascosto un canvas basta disabilitare la canvas component così non triggheriamo un redraw (ricordarsi di fermare il custom code nei figli se c’è)
Input events like onscreen touches or clicks require the GraphicRaycaster component. This simply loops through each input point on screen and checks if it’s within a UI’s RectTransform.
Remove the default GraphicRaycaster from the top Canvas in the hierarchy. Instead, add the GraphicRaycaster exclusively to the individual elements that need to interact (buttons, scrollrects, and so on).

Also, disable Raycast Target on all UI text and images that don’t need it. If the UI is complex with many elements, all of these small changes can reduce unnecessary computation.
