# Stutter when showing Monarch screen containing a Distance Field font with a shadow

**URL:** <https://forum.defold.com/t/stutter-when-showing-monarch-screen-containing-a-distance-field-font-with-a-shadow/64934>\
**Category:** Questions\
**Created:** [April 21, 2020, 4:26pm UTC](https://forum.defold.com/t/stutter-when-showing-monarch-screen-containing-a-distance-field-font-with-a-shadow/64934 "2020-04-21T16:26:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [April 21, 2020, 4:26pm UTC](https://forum.defold.com/t/stutter-when-showing-monarch-screen-containing-a-distance-field-font-with-a-shadow/64934/1 "2020-04-21T16:26:58Z")

</div>

I can’t seem to get rid of a stutter that happens when I show a Monarch screen for the first time. Subsequent monarch.show()'s are fine.

The “Preload” flag has been ticked, but this only seems to move the stutter a few frames earlier.

 ![33](https://forum-defold.b-cdn.net/uploads/default/original/3X/6/7/67a9d4d462069523d7c157003930a2f5fd7da95f.png)

The curious thing about this is that it happens for all screens, even if they’re virtually empty (one text node and one box node) and minimal code in the .gui\_script.

Aside from the above, is there anything else I could do to avoid this stutter?

Edit: Removing things in sequence until there was no stutter revealed the culprit: Shadow Alpha and Shadow Blur. When both set to 0, the stutter disappears. Is it possible to pre-cache the fonts?!

 ![59](https://forum-defold.b-cdn.net/uploads/default/original/3X/4/9/49dbef1e7b86b2893f5ff387ef76943d0b58a405.png)

Edit 2: Changing the font to Bitmap also removes the issue, but then the shadow doesn’t work (it becomes square blocks).

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [April 21, 2020, 8:19pm UTC](https://forum.defold.com/t/stutter-when-showing-monarch-screen-containing-a-distance-field-font-with-a-shadow/64934/2 "2020-04-21T20:19:05Z")

</div>

Does this happen when testing on desktop or on mobile?

> [@totebo](#):
>
> I can’t seem to get rid of a stutter that happens when I show a Monarch screen for the first time.

There’s a transition or something that stutters?

> [@totebo](#):
>
> Edit: Removing things in sequence until there was no stutter revealed the culprit: Shadow Alpha and Shadow Blur. When both set to 0, the stutter disappears. Is it possible to pre-cache the fonts?!

I have no idea why this happens… @jhonny.goransson or @JCash any idea?

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [April 21, 2020, 8:35pm UTC](https://forum.defold.com/t/stutter-when-showing-monarch-screen-containing-a-distance-field-font-with-a-shadow/64934/3 "2020-04-21T20:35:04Z")

</div>

> [@britzl](#):
>
> Does this happen when testing on desktop or on mobile?

iPhone 11 Pro, mostly. 😳

> [@britzl](#):
>
> There’s a transition or something that stutters?

First the phone freezes for 2 frames, then the FPS gets shaky for a few seconds, then comes back to normal. If no shadows are used, there is no freezing or FPS drop at all.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [April 21, 2020, 9:29pm UTC](https://forum.defold.com/t/stutter-when-showing-monarch-screen-containing-a-distance-field-font-with-a-shadow/64934/4 "2020-04-21T21:29:04Z")

</div>

Not sure why it would be that much heavier. SUre, each glyph has 3 layers instead of one.

As for caching, for each uncached glyph, we, upload the glyph texture to the larger cache texture.  
Before that, we unpack the glyph texture as well.

I guess if there are a lot of new glyphs to be uncompressed and uploaded the first frame, it will stutter.

We don’t have a handy preworming function currently yet.

You _should_ be able to prewarm it by incrementally adding a few glyphs to an (invisible/hidden) text node each frame.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [April 21, 2020, 9:37pm UTC](https://forum.defold.com/t/stutter-when-showing-monarch-screen-containing-a-distance-field-font-with-a-shadow/64934/5 "2020-04-21T21:37:22Z")

</div>

Since it’s a distance field, would it be enough to pre warm the glyphs at one point size, or would all used point sizes have to be cached separately?

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [April 21, 2020, 9:42pm UTC](https://forum.defold.com/t/stutter-when-showing-monarch-screen-containing-a-distance-field-font-with-a-shadow/64934/6 "2020-04-21T21:42:42Z")

</div>

At that stage, there is no point size, only the rasterized size that you chose for the font.  
So, for each fontfile you’ll have to prewarm.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [April 21, 2020, 10:23pm UTC](https://forum.defold.com/t/stutter-when-showing-monarch-screen-containing-a-distance-field-font-with-a-shadow/64934/7 "2020-04-21T22:23:44Z")

</div>

That’s great. Then my plan to cache all glyphs during loading might work. Will try it out tomorrow.

Edit: Ok, I’ve managed to get it to work! There is a caveat, though: The collection with the cached fonts needs to always be visible/in memory. If it’s unloaded, the stutter starts happening again.
