Page 1 of 1

[Android(?)] Slow font loading on some devices

Posted: Wed Feb 17, 2021 7:07 pm
by ohai
I'll spare you the long story, but my game is loading super slow on some mobile devices and after a (much too long) investigation I've found out what causes it. I still don't know why though, so here it goes:

Loading fonts (love.graphics.newFont(font, size)) takes quite a long time, but only on some devices. It doesn't seem to be dependent on their overall performance, as it behaves differently on similarly powerful ones.

Approximate full game loading times on different devices (measured from launch to the first rendered frame):
- 1s on Xiaomi Mi 9 (Android 10 "MIUI")
- 1s on Xiaomi redmi note 9 pro (Android 10 "MIUI")
- 2s on Xiaomi redmi 5a (Android 7 "MIUI")
- 3s on Xiaomi Redmi Note 8T (Android 10 "MIUI")
- 10s on Nokia 9 (Android 10 "Android One")
- 13s on Nokia 5.1 PLUS (Android 10 "Android One")
(I've also got some reports of slow loading from other people (friends of friends), but unfortunately I don't know exact times and what devices are they using.)

After finding out that font loading is the main issue, I've made more precise measurements on my Nokia 9:

Code: Select all

  resources.font = {}
  print("menu")
  resources.font.menu = love.graphics.newFont("fonts/dudeludel.ttf", 64)
  print("menuBig")
  resources.font.menuBig = love.graphics.newFont("fonts/dudeludel.ttf", 128)
  print("menuArrow")
  resources.font.menuArrow = love.graphics.newFont("fonts/poetsen.ttf", 275)
  print("menuCounter")
  resources.font.menuCounter = love.graphics.newFont("fonts/poetsen.ttf", 80)
  print("done")
and the result is:

Code: Select all

2021-02-17 19:44:06.945 11820-12029/org.ohaidev.snek I/SDL/APP: [LOVE] menu
2021-02-17 19:44:07.375 11820-12029/org.ohaidev.snek I/SDL/APP: [LOVE] menuBig
2021-02-17 19:44:09.115 11820-12029/org.ohaidev.snek I/SDL/APP: [LOVE] menuArrow
2021-02-17 19:44:12.589 11820-12029/org.ohaidev.snek I/SDL/APP: [LOVE] menuCounter
2021-02-17 19:44:13.024 11820-12029/org.ohaidev.snek I/SDL/APP: [LOVE] done
The fonts are:
- dudeludel (18 KB)
- poetsen(169 KB)

It looks like it takes longer to load a bigger font, which is understandable.
Why is it almost instant on some devices and so slow on others though, I have no idea. Does anyone know what may be causing it?

P.S. On my PC it loads almost instantly. I thought it was because of JIT being enabled on PCs by default, but jit.off() doesn't really change anything. At the moment I assume it doesn't affect PCs because of their higher overall performance, but I don't really know about that. Anyway, I've tagged the thread "Android(?)" because I'm not sure if it actually only happens on Android devices.

Re: [Android(?)] Slow font loading on some devices

Posted: Mon May 27, 2024 8:51 pm
by AR2
Hi ohai,

I just had this problem. I was working on my PC and had no problem whatsoever. However when I tested it in my phone (Motorola G6 plus) it run all slow. I started going back in my code because I had previously tested it on my phone and had no problem. Anyway like you mention it was due to the fonts. I was doing something even simpler, just changing the size of the fonts by calling love.graphics.setNewFont(size).

Anyway I googled the problem and your post was the first thing to come out. The third thing, was the page of the actual method:

https://love2d.org/wiki/love.graphics.setNewFont

Which has a note at the beginning:

"This function can be slow if it is called repeatedly, such as from love.update or love.draw. If you need to use a specific resource often, create it once and store it somewhere it can be reused!"

Maybe this was added after you post...

So I guess in my case I'll just move it so that it is not called all the time

Re: [Android(?)] Slow font loading on some devices

Posted: Tue May 28, 2024 3:19 am
by zorg
AR2 wrote: Mon May 27, 2024 8:51 pm ...
Considering that the wiki has those neat little history buttons for each page, I highly doubt that anyone's doing time travel shenanigans considering the OP's post was made in 2021, and the last edit to that page was in 2015.

The warning was added to the page with the last change in 2015, and it's only a caution against calling the function repeatedly each frame, because some might have not learned how love.update works...

also unlikely that OP would read this thread due to the low post count and that it's been 3 years since posting. :/