How to reduce save and load times

Discussion and help for Easy Save 3
RyanNguyen
Posts: 8
Joined: Wed Mar 15, 2017 4:39 pm

Re: How to reduce save and load times

Post by RyanNguyen »

Hi Joel,
What do I need to be able to use multiple threads to load a large amount of objects with Easy Save 3?
I have an idea that using 5 threads to instantiate 5000 objects, each thread will initialize 1000 objects is this possible and how can I do that?
For now I use this code to save and load game from Easy save 2
How can I use thread solution with this save and load code ?

Code: Select all

// To Save.
using(var writer = ES2Writer.Create("myFile.txt"))
{
    writer.Write(CreatedObjects.Count);
    foreach(var uniqueID in CreatedObjects)
    {
        writer.Write(uniqueID.id);
        writer.Write(uniqueID.prefabName);
        writer.Write(uniqueID.transform);
    }
    writer.Save(false);
}

// To Load.
using(var reader = ES2Reader.Create("myFile.txt"))
{
    int count = reader.Read<int>();
    // Optional: You may want to destroy each object in the createdObjects list and clear the list here
    // to prevent duplicates. I haven't done so in this example however.

    for(int i=0; i<count; i++)
    {
        int id = reader.Read<int>();
        string prefabName = reader.Read<string>();

        // Get your prefab and instantiate it.
        var prefabInstance = UniquePrefabManager.InstantiatePrefab(prefabName);
        // Read the Transform into the prefab instance's Transform using self-assigning load.
        reader.Read<Transform>(prefabInstance.transform);
    }
}
Thank you Joel.
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to reduce save and load times

Post by Joel »

Hi there,

You would only need to create one thread to do your saving and loading in, not multiple threads.

For more information on threads I recommend looking at tutorials online. For example, this one (this is not affiliated with us).

Be aware that although Easy Save is thread safe, the data you're saving might not be, so might not work with threads.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Michal.Stangel
Posts: 10
Joined: Mon Mar 18, 2019 3:12 pm

Re: How to reduce save and load times

Post by Michal.Stangel »

Hello,

It's great that it's possible to have more cached files for loading at the same time. I have game save file opened and meantime some other stuff is being loaded from different files.

But I've been wondering if I should do some cleaning once loading from cached file is done? Before, when using traditional loading from File, I've just set file to null at the end.

Code: Select all

ES3File file = new ES3File(fileName);
bool result = file.Load<bool>(loadKey);
file = null;
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to reduce save and load times

Post by Joel »

Hi there,

If you're using ES3File then setting it to null is fine.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Michal.Stangel
Posts: 10
Joined: Mon Mar 18, 2019 3:12 pm

Re: How to reduce save and load times

Post by Michal.Stangel »

Thanks, but it was my previous setup. Now I use cache files and here I am not sure if this is enough:

Code: Select all

ES3.CacheFile(fileName, settings: saveSettings);
bool result = ES3.Load<bool>(loadKey, fileName, saveSettings);
No cleaning at the end necessary?
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to reduce save and load times

Post by Joel »

Hi there,

If you're using the caching save location then you can use ES3.DeleteFile to remove the file from the cache.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Michal.Stangel
Posts: 10
Joined: Mon Mar 18, 2019 3:12 pm

Re: How to reduce save and load times

Post by Michal.Stangel »

But it just deletes file I stored to the disk with StoreCachedFile :-)
ES3.StoreCachedFile(fileName, settings: saveSettings)
ES3.DeleteFile(fileName, settings: saveSettings);
I guess there is no need to clean memory then?
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to reduce save and load times

Post by Joel »

Hi there,

Does your 'saveSettings' ES3Settings have the save location set to Cache?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Michal.Stangel
Posts: 10
Joined: Mon Mar 18, 2019 3:12 pm

Re: How to reduce save and load times

Post by Michal.Stangel »

I do. But I probably used same settings also for different loading which deleted the file. My fault.
Thanks again.
Post Reply