I’m looking into the viability of switching from Coherent UI (essentially a webkit browser) to uGUI on iOS/Android. My app is very UI & image heavy (more like facebook than a normal 3D game) so I wanted to prepare a representative test. I wanted to check the test would be “fair” so I’m looking for feedback on best practices in this scenario. Hopefully others will find the info useful when implementing something like this for real.
The most intensive thing I thought of mocking up quickly is taking a directory of n hi-res thumbnails (think retina) in a 2 or 3 wide grid and scrolling through. This puts a lot of pressure on other elements of Unity3d outside uGUI (loading and encoding textures) but for my purposes thats part of what I’m testing and it can also be circumvented by loading up front if I just want uGUI rendering benchmarks.
It seems other people have struggled encoding images to textures on mobile (which is odd when it happens in a negligible amount of time in the browser in hardware accelerated mode). This thread has the most useful info on that process Texture2d.LoadImage too slow for use (iOS) - Questions & Answers - Unity Discussions
Using .texture [instead of LoadImage] cuts the load time for me down from 250ms to 50ms, .textureNonReadable cuts this down further to under 20ms.
I’m also tempted to store the thumbnails as bytes in ARGB or a more compressed format, and pretend we have the full res jpeg saved somewhere if we need the quality later, or if it needs to be shared to the web.
This article suggests that www.texture loads arent very memory friendly, and a way to manage that Unity3D: loading external images | Kyr Dunenkoff
All together this makes me think the system should read the folder contents into a list and generate some uGUI thumbnail sprites in a scrollable area, loading in those files that are visible.
When the user scrolls the system should assign a number of www loaders that begin loading via coroutine if an “empty” thumbnail sprite is close to the leading edge of the scrollable area, until all the thumbnails are loaded or the frame time is over a time threshold (like 14ms). At least one image should be loaded so we are making progress each frame.
On the trailing edge of the scrollable area, the thumbnail sprite textures are destroyed and the thumbnail objects themselves added to the leading edge ready to come into view (thereby limiting the number of objects to the number required to fill the view + a few rows either side for loading into).
Does this sound like a reasonable implementation to test against Coherent UI? Is it over-engineered (in that Unity3D would handle some of the optimisations automatically)? Is there any other low-hanging-fruit I’m missing in terms of optimisation?