Identifying Screen Creation Performance Issues
Last updated
Was this helpful?
Last updated
Was this helpful?
If you have a screen which seems to take a long time to load then this can be the cause of either long load times in generated code or a slow CustomInitialize function. The first step in fixing the problem is to identify whether it is custom or generated code.
CustomInitialize can be measured easily by using the property along with the function. For this example, let's assume a simple CustomInitialize which looks like this:
The actual contents of CustomInitialize don't really matter - this is just some sample code that we can use to show how to measure CustomInitialize time. To measure and output the time, we'll need to do 3 things:
Record the current time at the start of the function
Record the current time at the end of the function
Print out how long the initialize took by subtracting the beginning time from the end time
CustomInitialize can be modified to do this as follows:
The example above tells us how long CustomInitialize takes, but it doesn't tell us how long generated code took to execute. This is important if your CustomInitialize code is fast (like less than 1 second) but the Screen still takes a long time to load. We can ask Glue to give us more detailed information to solve this. The steps to solve this are:
Turning on detailed performance logging in Glue
Modifying your code to output load times
To do this:
Switch to glue
Select "Settings"->"Performance Settings"
Set "RecordInitializeSegments" to "True"
Click "Done"
Now Glue will generate code to measure Screen initialization time. Next we'll output this information on-screen.
To do this:
Switch to Visual Studio
Open your Screen that you want to measure the initialization times on
Go to CustomActivity (not CustomInitialize)
Add the following code in CustomActivity:
So far we've discussed how to measure where slowdowns are occurring.
Your game should now output information about initialization time: Notice that this output method uses exponential notation for very small values. For example in the image above GameScreenPooled PostInitialize took "4E-07". This is the equivalent of 4 * 10^(-7), or in other words 0.0000004. Typically if you see exponential notation you are dealing with time values which are so small that they will not have much if any of an impact on performance, so they can be treated as if they're 0. If the output from ToStringVerbose is too large to view on screen you can also output this to the Visual Studio output window as follows:
If the slowdown is in CustomLoadStaticContent or LoadStaticContent (notice the name of your screen will be prefixed), then you can solve the problem either by loading less content or by using a loading screen. For more information on using loading screens, see .