Saving sprites takes a long time

Discussion and help for Easy Save 3
Post Reply
User avatar
fanaei
Posts: 26
Joined: Thu Aug 23, 2018 7:54 am

Saving sprites takes a long time

Post by fanaei »

Hi Joel
Recently I noticed that saving sprites and textures takes a long time. Is there any way to fix it or at least making this time shorter?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving sprites takes a long time

Post by Joel »

Hi there,

Sprites and Textures will generally take a long time to save and load because it has to compress and store the image data. Unless the pixels of your images are changed at runtime, it's recommended to store a reference to them rather than the Textures/Sprites themselves.

However, if you do need to store the Texture data itself, I recommend only saving Textures and Sprites to their own individual files. If you have multiple keys in a file, Easy Save will need to navigate to that point in the file before loading it. When you have a large amount of data in the file, the buffer might have to be refilled multiple times to get to that point.

On a similar note, you might also want to increase the buffer size in Window > Easy Save 3 > Settings. By default it is 2048 bytes which is great for loading most things, but perhaps too small for loading Sprites. Try checking the size of your file and raising this to something just above the size of your file (or 1,000,000 if you're not sure how big your files will be, as this will cover you for anything up to 1MB).

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
User avatar
fanaei
Posts: 26
Joined: Thu Aug 23, 2018 7:54 am

Re: Saving sprites takes a long time

Post by fanaei »

Thanks Joel
I'm making my game for android. And sometimes saving or loading sprites takes more than 1 minute! and even sometimes it stuck there!
Btw... What about location? Does any of location options affect on performance of saving process?
Also, can I show a saving progress or animation during saving process?
And what's the best compression option for saving sprites? Is it better to compress it or not? Because when I use crunched, It gets saved but I get an error:

Code: Select all

'ETC2_RGBA8Crunched' is not supported on this platform. Decompressing texture. Use 'SystemInfo.SupportsTextureFormat' C# API to check format support.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving sprites takes a long time

Post by Joel »

Hi there,

Generally ARGB32 or RGB32 are the best options for compatibility, but as far as I'm aware this won't change the size of the Texture when it's serialised.

With regards to showing progress, it's not possible to know how long serialisation will take until it has actually happened, so it wouldn't be possible to show progress. However, you can run Easy Save in a separate thread so it doesn't block the main thread, and show a 'fake' loading bar if you wish.

Just to clarify, location won't have an effect on performance because ultimately it is all stored to file on Android, and the main bottleneck is compressing the Texture so that it can be stored.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
User avatar
fanaei
Posts: 26
Joined: Thu Aug 23, 2018 7:54 am

Re: Saving sprites takes a long time

Post by fanaei »

Thanks. Multi threading is a good idea. But as I'm not an advanced programmer, it can be a bit hard to implement it. Do you know any thread in this forum or any other tutorial than can help me? (I googled about it, but I thought maybe you know something better.)

Also it's my code for saving sprites in my inventory with almost 30 item slots. I thought maybe my codes also have some problems that made the saving process too long.

Code: Select all

ES3.Save<Sprite[]> ("itemBigPic", itemBigPic);
		ES3.Save<Sprite[]> ("CombinedBigPic", CombinedBigPic);
		ES3.Save<Sprite[]> ("CombinedImage", CombinedImage);

		for (int i = 0; i < Items.Length; i++) {
			ES3.Save<Sprite>("itemImageSp"+ i, itemImages[i].sprite);
			ES3.Save<bool> ("ItemImageBool" + i, itemImages [i].enabled);
		}
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving sprites takes a long time

Post by Joel »

Hi there,

You're saving all of your sprites to the same file, which is likely the cause of the issue (see my first reply).

For each of your ES3.Save/ES3.Load calls you should specify a different filename. For example:
ES3.Save<Sprite[]> ("itemBigPic", itemBigPic, "itemBigPic.es3");
ES3.Save<Sprite[]> ("CombinedBigPic", CombinedBigPic, "CombinedBigPic.es3");

itemBigPic = ES3.Load<Sprite[]> ("itemBigPic", "itemBigPic.es3");
CombinedBigPic = ES3.Load<Sprite[]> ("CombinedBigPic", "CombinedBigPic.es3");
This will remove the performance penalty of random access.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply