Unity 3D: Asset Bundles vs. Resources folder vs www.Texture - caching

So, I've done a bit of reading around the forums about AssetBundles and the Resources folder in Unity 3D, and I can't figure out the optimal solution for the problem I'm facing. Here's the problem:
I've got a program designed for standalone, that loads "books" full of .png and .jpg images. The pages are, at the moment, the same every time the program starts. At the start of the scene for any "book", it's loading all those images at once using www.texture and a path. I'm realizing now, however, that this is possibly an non-performant method for accessing things at runtime -- it's slow! Which means the user can't do anything for 5-20 seconds while the scene starts and the book's page images load up (on non-legendary computers). SO, I can't figure out which of the three things would be the fastest:
1) Loading one asset bundle per book (say 20 textures # 1 mb each).
2) Loading one asset bundle per page (1 mb each).
3) Either of the first two options, but loaded from the resources folder.
Which one would be faster, and why? I understand that asset bundles are packaged by unity, but does this mean that the textures inside will be pre-compressed and easier on memory at load time? Does the resources folder cause less load time? What gives? As I understand it, the resources folder loads into a cache -- but is it the same cache that the standalone player uses normally? Or is this extra, unused space? I guess another issue is that I'm not sure what the difference is between loading things from memory and storing them in the cache.
Cheers, folks...

The Resource folders are bundled managed assets. That means they will be compressed by Unity, following the settings you apply in the IDE. They are therefore efficient to load at runtime. You can tailor the compression for each platform, which should further optimize performance.
We make expensive use of Resources.Load() to pull assets and it performs well on both desktop and mobile.
There is also a special folder, called StreamingAssets, that you can use to put bundled un-managed assets. This is where we put the videos we want to play at runtime, but don't want Unity to convert them to the default ogg codec. On mobile these play in the native video player. You can also put images in there and loading them is like using WWW class. Slow, because Unity needs to sanitize and compress the images at load time.
Loading WWW is slower due to the overhead of processing asset, as mentioned above. But you can pull data from a server or from outside the application "sandbox".
Only load what you need to display and implement a background process to fetch additional content when the user is busy going through the first pages of each book. This would avoid blocking the UI too long.
Optimize the images to reduce the file size. Use tinypng, if you need transparent images, or stick to compressed JPGs
Try using Power of 2 images where possible. This should speed up the runtime processing a little.
ath.

Great answer from Jerome about Resources. To add some additional info for future searches regarding AssetBundles, here are two scenarios:
Your game is too big
You have a ton of textures, say, and your iOS game is above 100 mb -- meaning Apple will show a warning to users and prevent them from downloading over cellular. Resources won't help because everything in that folder is bundled with the app.
Solution: Move the artwork you don't absolutely need on first-run into asset bundles. Build the bundles, upload them to a server somewhere, then download them at runtime as needed. Now your game is much smaller and won't have any scary warnings.
You need different versions of artwork for different platforms
Alternative scenario: you're developing for iPhone and iPad. For the same reasons as above you shrink your artwork as much as possible to hit the 100 mb limit for iPhone. But now the game looks terrible on iPad. What do?
Solution: You create an asset bundle with two variants. One for phones with low res artwork, and one for tablets with high res artwork. In this case the asset bundles can be shipped with the game or sent to a server. At run-time you pick the correct variant and load from the asset bundle, getting the appropriate artwork without having to if/else everywhere.
With all that being said, asset bundles are more complicated to use, poorly documented, and Unity's demos don't work properly at times. So seriously evaluate whether you need them.

Related

What is the best practice for image compression

I am receiving control of a website and I need to take care of an image compression process.
Right now, when uploading an image, it gets stored on the server with high quality and when the website's being cached, the image is getting compressed for the cache. So the cache has a compressed copy of the image while the original, high quality image, is still stored on the server.
The tool which is responsible of doing what I have just described was developed by the current owner of the website and since I am not getting that tool I will need another one. The site is currently using Pydio and I have not seen any compression option there.
Since it seems I need a new tool for the image compression process, I want to know first what is the best practice, performance-wise, for handling the compression and I know there some good, experienced developers here.
I thought about some options:
Keep it the way it is now, which is to store the original image on the server and when caching, compress it for the cache (Best compatibility with the website since this is what the tool currently being used doing).
Compress all images the moment they are being uploaded and so I will have only the compressed images on the server and use them to cache (Save storage space, but don't know how to combine it with Pydio).
Have a cron which will compress all the images which are not already compressed (Gives me the ability to upload images freely without worrying about compressing them, though the images will not be immediately compressed).
Upload the image to a website which compresses the image and then take the outputted image and upload it (Really, sounds stupid and a lot of messing around in order to upload an image)..
What do you think will be the best practice, and why? Also, Is there a better practice for compressing the images?
Plus, if you know any tool which has an API for it or anything, I will be thankful to hear about it.
The website is built using PHP.
Since the question you're asking is a general-approach one, I will put my two-cents in.
On your approaches:
Option 4 - You could use some offline software or an external site for compression, but it seems tedious work. If I needed to upload one image per day, I would probably choose this option.
Option 2 - I would rather not do compression on upload since you lose the original image. Image compression can ruin some images very badly.
As for options 1&3 - I think it depends on the resources of your server, the number of images, the traffic of your site, etc. Generally, I prefer compressing/caching on request, not upload, but for a smaller site, it shouldn't make much difference.
As for the API - generally, you have two options: do the work on your server/site or use an external service.
When it comes to services, we use CloudImage, it has very simple API and it helps a lot with the compression process (and resizing if you need it). Also, you have the benefits of the CDN, which will boost the performance. Since you are using Pydio, I assume you need data security and privacy, so CloudImage may be a good option for you since they take the privacy stuff really seriously.
If you prefer to do this yourself, and given that you use PHP, I would recommend ImageMagick and the PHP library IMagick. You can control every parameter of the compression and the documentation is pretty good. The only downside is that to achieve best compression without losing quality, it is a bit of trial-and-error at first.
Good luck!
Send your image on Whatsapp to other, received Image will be compressed to the significance size

Manage resource images in Xamarin forms

I have been working on Xamarin forms for a long time now but the thing that has always bugged me is what is the better approach to store images in xamarin forms.
I wanted to know which images should I use from PCL and which ones should I put in native resource files or is using PCL images a bad approach altogether.
I went through everything in Local Images and Embedded Images but found nothing related to the better approach among them or performance or anything as such.
At the end after all the research for almost a year I came to the conclusion that the Local Image approach suits me better, even with the case where I had to add it to all three native projects depending what I target.
Reason being the following:
When I use local images I have an option to place different images in different size folders i.e. HDPI, MDPI(Android) and #2x,#3x(iOS)
What the above point does for me is it selects the image it should pick as per the current devices resolution which cannot be achieved with EmbeddedResources
One possible solution to issue mention above was using SVG's but as everyone knows that if the image you are using needs to look pixel perfect SVG's are not your best option as they lose some details here an there as you use them in your mobile devices.
One more cheeky thing I did (but I like to share my dev secrets) was whichever Images in my application were only in one size for all resolutions and platform or at least two of them I incorporated them in the Shared code
Note: Embedded Resource takes a little more time to load then your native Local Images always consider that while using

How do you generate an Image in a Windows Phone Scheduled Agent?

I need to generate an imaged based on data returned from a WebService call within a PeriodicTask in a Windows Phone app (Mango+).
I've seen a few ways of doing it in the main app but nothing that seems to work from a Scheduled Task
It depends. If you're in a background agent, memory is precious. The libraries you load count against your allocation limit, too, so you have less than the advertised amount.
Do you have a base image that you're modifying? If so, avoid creating UI elements and try to work with a WriteableBitmap. There is a library (yes, memory, but it's incredibly useful) that provides useful methods for working with such images called WriteableBitmapEx.
If you're generating simple images from scratch, going the UserControl route is workable too.
Try this guide I've described on my blog:
http://suchan.cz/?p=110
Basically you have to create your own UserControl and then render it into image and save it either as jpg, without transparency, or as transparent png. Also make sure you use as low memory as you can in the Backgroud Agent, if you use more than 6MB in WP7 or 11MB in WP8, your periodic task will be killed without notice.
I use a utility called ImageTools to render a PNG from a user control (note, this is not my blog). I created a shared library, with references to ImageTools, ImageTools.IO.Png, and ImageTools.Utils. The shared library does all the heavy lifting. Then my background agent project references the shared library project, and in the ScheduledAgent.OnInvoke it calls into the shared library to do the work. I am on Windows Phone 8 but it seems to work very well.

Performance issues with images in Blackberry app

I am developing one Blackberry application. In that application i am using lot of images both downloading from server as well as inside application using images for designing image button. My application working fine until continuously using 3 to 4 minutes.After that my application performance was too bad. My question is how to optimize memory to improve my application performance?
Thanks in Advance.
A pure guess - you are keeping the downloaded images in RAM, even if you don't use them on your current screen. If this is the case, then try to save them to the file system and read only those you're actually use for the current screen.
Unfortunatelly we can only guess, while it'd be much better to do it in a professional way. First of all you should detect your real reason. For this you should monitor your app to see what kind of objects eat most of the memory. And also how memory state changes in time. I work in JDE and it has a built-in tool for such kind of monitoring: 'View' > 'Object Statistics' (or 'Memory Statistics'). To activate those items you have to start your app in debugger. When you know the reason, you can go further and actually fix your code.
Use Eclipse Blackberry plugin profiler to find out if its memory or cpu performance issues.
If there are images in resources you are using constantly for UI elements, it's better to load them on app start and save them into some static constants. This way you will save CPU from loading images from resources.
Also consider convert images in resources into PNG with the 565 colorspace

Project is growing ang growing, Xcode slowing down

My projects is growing. It includes about 16 thousands .m4a (sound) files, because it's the App helping to learn languages with examples, but only few classes and files containing code.
Since I 've added those 16000 files working on this project is PITA. Renaming any file takes time, compiling, building, launching the app takes so much time. Of course I know that about 200MB has to be transfered, but the problem is the compouter is responding badly at that time.
Fortnately I have a SSD drive and 8GB RAM, I don't want to even think, how long would it take on HDD.
Is there any way to improve the perfomance?
I'll be also responsible for creating more than a ten similar apps for other pair of languages, and I would like to have all of them in one project and only play with targets. So if I don't do anything with performance now, there is high probability than one day I'll throw away this computer through the window of my house on the 2nd floor...
You can try downloading each m4a from the web once you need it. means - the app will be thin when a user download it, but once a sound file have to be played - it'll be downloaded from the web and saved on the SD. next time you have to play this file - play it from the SD.
And yeah, XCode have many problems - this is one of them..
I have solved the problem, by creating an additional Core Data sqlite file, that contains all of the resources, so the entity looks like:
name (nsstring) - name of file
data (nsdata) - binary of file
works like a charm. Quick builds, quick debugs, just like before.

Resources