I'm working on a traditional roguelike project. I have a player log that displays what happens, played moved here, robot attacked player, player casts ability etc. This is fairly useful information and it updates frequently, every time the player takes an action at least one line will be generated and if there are any enemies around they too will generate lines.
I'm using a TMP wrapped inside a Viewport that is inside a scroll rect to display the last 10 or so lines of the log, and the scroll rect gives us the ability to scroll back up to look at previous lines.
Originally, I would naively add lines to the TMP.text and this would just grow, but, I quickly noticed performance issues, whenever text was appended the TMP.GenerateTextMesh/GenerateText calls would quickly grow in magnitude to the point where it was visibly slowing the game down after one hundred lines or so.
So to partially fix the problem I now store the log's text in a rotating circular buffer and keep only 20 or so lines in the TMP.text that makes the performance fine-ish. But that .text value still needs to change when new lines are added or the user scrolls to look at old lines. Even with a relatively small amount of text, 20 or so lines, the calls for TMP.GenerateText are taking around ~10ms (with deep profiler on) which is an insane cost for a relatively simple piece of UI. The cost is per update, so once made the text is cheap to render, but if you have a text field changing frequently the cost is exorbitant.
Is there a better solution to display a dynamic text field with frequently changing content? I'd imagine anything with a chat client is facing similar issues so there must be a solution.