Is this normal with Text Mesh Pro ?

Hi,

I have made a very simple game. In the game after certain time I activate a canvas with few UI elements on it.(buttons and text). During profiling I found that text mesh pro is genrating lot of garbage. (check the attached image)
The frame rate stays at 200 fps for most of the game but only for 2-3 frames it becomes 15 fps when I am activating a canvas with text on it.

Is this behaviour normal ? How to fix this?

When the first text object is awakened, certain resources like font assets, sprite assets, etc. need to be loaded along with managers. Then the text object itself needs to allocate its own buffers and depending on how many characters this text object contains, this will vary.

There are also allocations related to the Canvas system, etc.

Once these resources have been loaded, only new text object instantiation or changes in the number of characters needing to be displayed will result in additional allocation to grow the buffers of those text objects to accommodate the increase number of characters.

Static text objects or text objects changing every frame where the number of characters doesn’t exceed the block allocation (power of two) will result in no / zero allocation.

So, worst case scenario is when the first text object is created and awaken with large quantity of text. This overhead should only occur once. You might want to experiment with on scene loading to create / awaken the first text object or some dummy text object with string.Empty to force loading the resources and managers which will shift this overhead to when the scene is loaded as opposed to when the first text object is enabled.