Updating Label causes stuttering on android

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By misterej

I tried to find the source of the stutters and narrowed down it to this.

Basically when I update the text on a Label the game stutters.

extends Label

func update_score():

I call this function every time the score Label needs to be updated

even when i do this it stutters:

extends Label

func update_score():

It happens for about the first 5 seconds or so when the score is updated.
After those 5 seconds it updates without stuttering.
It only happens when I export it to android. If i run it on my pc it doesn’t stutter

I’m using godot 3.2.2 stable

:bust_in_silhouette: Reply From: misterej

I ran a profiler on my project and figured out that the Idle Time was spiking.
I think that it was spiking because the font data on my label wasn’t preloaded or cached. So everytime I had a new symbol be displayed the font data had to be fetched.

Basically every new symbol that I used had to be loaded seperately.

I solved it by creating another label and just printing every numeral “0123456789” and the stutters stopped except after the first score update.

There should be a better way of solving this.

There’s a pull request that aims to make DynamicFont caching easier: https://github.com/godotengine/godot/pull/40491

PS: You should be able to set the label’s Modulate property to Color(0, 0, 0, 0) so it’s invisible while still rendering its characters.

Calinou | 2020-07-25 10:11