[Graphics 1.0] Seeing poor performance when drawing objects

Hey folks,

A little note upfront, I’m working on a project that is still using Graphics 1.0, as it was in development before Graphics 2.0 was released and I wasn’t confident about migrating mid-project.  To be specific, I’m working off of Version 2013.1202.

That being said, I’m having an issue optimizing portions of the game where small popups and similar smaller menus are drawn as needed.  With respect to the optimization documentation, I unload and re-draw these menus as needed so that they are not constantly held in memory.  However, I’m seeing some significant lag time on devices that I wouldn’t expect to see issues running this (iPhone4S and iPhone5, for example).  I recently downloaded the Corona Profiler to identify which parts of the code where causes the lag I was seeing, and the bulk of the processing time is spent on the base display class when drawing elements, so display.newImage(), display.newImageRect(), display.newText(), etc.

I’ve tried other things, like making some textures smaller (I have a large texture that I use for the background of the app) to see if that would alleviate some of this lag that I was experiencing.  But, I took that 640x1136 background image and made it into a 288x512 and saw very little difference in processing time (~2ms faster).  Then I took that and reduced it to a 144x256 and saw the same result.  I know this would certainly help reduce my memory requirements, but I’ve checked my memory performance and the app is currently in a solid spot as far as the graphical memory being used.

At this point, I haven’t found a great way of optimizing the amount of time and processing it takes to actually draw content to the screen.  However, that is resulting in some poor performance for me, even for drawing a simple popup with 5 buttons, a header text, and one small texture (4x4) stretched to be the background for these elements.

In other engines and languages, I’ve been accustomed to declaring most of my assets up front and then hiding what I don’t need at that time (assuming I have enough memory to do so) simply because memory allocation is one of the most expensive operations.  I initially assumed to do the same in Corona, and draw these tertiary screens and menus at the start of the app and them simply hiding them and only rendering them when they need to be displayed to the user.  However, I didn’t end up going this route due to the optimization guide.  I’ve tried this method in small sections and the menus rendered much faster once they were already allocated at the start of the app and only displayed as needed, with the downside of the initial loading process taking longer as its creating and allocating these assets upfront.

I’d like to hear what options others have taken and if this is a common issue or if I should be looking at other areas for issues (although I can’t find anything thats eating nearly as much processing with the Corona Profiler as the base display class).  The dangers of never unloading these assets is of course that users are more likely to run out of memory due to the amount of assets/textures being held in memory, so I’d rather not go this route if I don’t have to, but I’m having difficulty getting these simple popups and menus being rendered without very noticeable lag on devices.

Any help would be greatly appreciated! 

“In other engines and languages, I’ve been accustomed to declaring most of my assets up front and then hiding what I don’t need at that time” I thought the exact same thing but I hit a similar problem. This is not a good idea in Corona, if you have too many display objects.

How many display objects have you created when the program is running slowly?

How is the slowdown happening? Is the user interface unresponsive? My problem was, that I created too many display objects. Even when setting the isVisible flag to false, I had terrible problems with the responsiveness of the touch screen. You might have to consider not hiding but cleaning out the invisible objects and load them in on the fly. It’s not a problem with disk access, since the graphics will have been loaded into memory only once, just that internally, it seems that the corona engine cannot handle too many display objects existing at once even though they are not being displayed.

“In other engines and languages, I’ve been accustomed to declaring most of my assets up front and then hiding what I don’t need at that time” I thought the exact same thing but I hit a similar problem. This is not a good idea in Corona, if you have too many display objects.

How many display objects have you created when the program is running slowly?

How is the slowdown happening? Is the user interface unresponsive? My problem was, that I created too many display objects. Even when setting the isVisible flag to false, I had terrible problems with the responsiveness of the touch screen. You might have to consider not hiding but cleaning out the invisible objects and load them in on the fly. It’s not a problem with disk access, since the graphics will have been loaded into memory only once, just that internally, it seems that the corona engine cannot handle too many display objects existing at once even though they are not being displayed.