Text render speed problem

Hi,

I noticed that text is being rendered very slow (much slower than images). I’ve tested it on emulator and on device and it always slows down whole app.

Here’s example app from Corona (table view example) which runs extremely slow on my device. Do you have any idea how to work around it? My app is mainly based on text so any help will be highly appreciated :/.

Regards

What device are you testing on?

Windows Phone x8 by HTC.

http://www.htc.com/us/smartphones/htc-wp-8x/#/

It’s not the best on the market but should be enough.

I currently don’t have any Windows phone myself, but I’d expect that one to be OK for table view scrolling…
Hopefully someone else with other devices can chime in with some advice.

m.czekala - If I remember correctly, we have found that the performance of certain text APIs is much slower on WP8 than on iOS/Android. In this case, are you just using the same code from another Corona project and building for WP8? If so, I suspect that is the problem.

Let me ask someone to take a quick look at this post.

Hi,

I found out the problem on my app which was written for iOS, but after that I tested it on examples from coronalabs and it was the same so it’s not directly related to my app.

Hope you will be able to help ass all seems to work great apart from this part which unfortunalely is the biggest part of my app (I mean text api).

Thanks

Yes, text bitmap generation is extremely expensive on WP8.  Far more expensive than iOS and Android.  We’ve already optimized it the best that we can and it’s not going to get any better.  Unfortunately, the performance issue comes from Microsoft’s native API end, not Corona’s.

The only way to work-around this is to use “bitmap fonts”, which is what Microsoft recommends and is what most AAA game studios use when displaying text that are updated frequently.  The reason bitmap fonts are faster is because all of the characters are pre-loaded in a single spritesheet/imagesheeet and text is then formed/layed-out based on those already loaded characters.  There are 3rd party bitmap font tools that can help you with this such as TextCandy, bmGlyph, Font-Manager, etc.  In fact, using them will improve the text update performance on Android as well. 

That said, the bitmap font technique is only useful for text that is under your control.  That is, it should only be used when you can guarantee that the characters you are using exist in your spritesheet.  The display.newText() function should be used for text that’s out of your control, such as text taken from the Internet like Facebook, Twitter, etc… and this will work fine in this case because you’re not going to be updating this text on every frame.

That’s really sad :(. Ok I will try to use sprite font but it’s probably not a good fit for apps as there’s always a lot of text.

Thanks again.

Regards

The important thing to note about the display.newText() function is that every time you create text with it, or update its text, it has the OS drawing text to a new bitmap and then submit that bitmap as a texture to the GPU.  That bitmap and GPU texture generation is an expensive operation on all platforms.  Meaning that doing so frequently will affect the framerate on all platforms.  It just happens to be most expensive on WP8.  If you switch to bitmap fonts, then you’ll find that you’ll get a better framerate on all platforms, not just WP8.

Case in point, on Android, if you display an FPS counter via an “enterFrame” event and display.newText(), then you’ll find that this can hurt the framerate as well.  This is a common tech-support issue for us and we often recommend developers to print() the FPS instead or use bitmap fonts.

But that said, the display.newText() function does have its advantages.  Since that function has the operating system render text, then you’re leveraging all of the hard work that Microsoft, Apple, and Google have done to implement properly localized text rendering.  Particularly for Asian text which has more symbols than you can fit into an image sheet in memory… or Arabic which is cursive text and difficult to construct via bitmap fonts.  Plus, when it comes to multiline text, the operating system already knows where to inject the line break when wrapping text for different languages.  So, these are the pluses of this functionality that I’m pretty sure that other SDKs such as Unity and Cocos2d-x do not offer (I believe they only offer bitmap fonts based on my conversations with Microsoft).  In Corona, we provide both types of text rendering, which is a huge advantage.

Anyways, that’s my 2 cents.  Hope that helps you out.

What device are you testing on?

Windows Phone x8 by HTC.

http://www.htc.com/us/smartphones/htc-wp-8x/#/

It’s not the best on the market but should be enough.

I currently don’t have any Windows phone myself, but I’d expect that one to be OK for table view scrolling…
Hopefully someone else with other devices can chime in with some advice.

m.czekala - If I remember correctly, we have found that the performance of certain text APIs is much slower on WP8 than on iOS/Android. In this case, are you just using the same code from another Corona project and building for WP8? If so, I suspect that is the problem.

Let me ask someone to take a quick look at this post.

Hi,

I found out the problem on my app which was written for iOS, but after that I tested it on examples from coronalabs and it was the same so it’s not directly related to my app.

Hope you will be able to help ass all seems to work great apart from this part which unfortunalely is the biggest part of my app (I mean text api).

Thanks

Yes, text bitmap generation is extremely expensive on WP8.  Far more expensive than iOS and Android.  We’ve already optimized it the best that we can and it’s not going to get any better.  Unfortunately, the performance issue comes from Microsoft’s native API end, not Corona’s.

The only way to work-around this is to use “bitmap fonts”, which is what Microsoft recommends and is what most AAA game studios use when displaying text that are updated frequently.  The reason bitmap fonts are faster is because all of the characters are pre-loaded in a single spritesheet/imagesheeet and text is then formed/layed-out based on those already loaded characters.  There are 3rd party bitmap font tools that can help you with this such as TextCandy, bmGlyph, Font-Manager, etc.  In fact, using them will improve the text update performance on Android as well. 

That said, the bitmap font technique is only useful for text that is under your control.  That is, it should only be used when you can guarantee that the characters you are using exist in your spritesheet.  The display.newText() function should be used for text that’s out of your control, such as text taken from the Internet like Facebook, Twitter, etc… and this will work fine in this case because you’re not going to be updating this text on every frame.

That’s really sad :(. Ok I will try to use sprite font but it’s probably not a good fit for apps as there’s always a lot of text.

Thanks again.

Regards

The important thing to note about the display.newText() function is that every time you create text with it, or update its text, it has the OS drawing text to a new bitmap and then submit that bitmap as a texture to the GPU.  That bitmap and GPU texture generation is an expensive operation on all platforms.  Meaning that doing so frequently will affect the framerate on all platforms.  It just happens to be most expensive on WP8.  If you switch to bitmap fonts, then you’ll find that you’ll get a better framerate on all platforms, not just WP8.

Case in point, on Android, if you display an FPS counter via an “enterFrame” event and display.newText(), then you’ll find that this can hurt the framerate as well.  This is a common tech-support issue for us and we often recommend developers to print() the FPS instead or use bitmap fonts.

But that said, the display.newText() function does have its advantages.  Since that function has the operating system render text, then you’re leveraging all of the hard work that Microsoft, Apple, and Google have done to implement properly localized text rendering.  Particularly for Asian text which has more symbols than you can fit into an image sheet in memory… or Arabic which is cursive text and difficult to construct via bitmap fonts.  Plus, when it comes to multiline text, the operating system already knows where to inject the line break when wrapping text for different languages.  So, these are the pluses of this functionality that I’m pretty sure that other SDKs such as Unity and Cocos2d-x do not offer (I believe they only offer bitmap fonts based on my conversations with Microsoft).  In Corona, we provide both types of text rendering, which is a huge advantage.

Anyways, that’s my 2 cents.  Hope that helps you out.