Page 1 of 1

Save file/string size part deux

Posted: Sat Jun 16, 2018 10:58 pm
by jinxology
Hey Joel,

I had previously asked about save file size, but I need a little help understanding the size of the string exported by ES3.LoadRawBytes (and presumably the stored save file size). For some background, in my RPG, I was previously saving the name of each item the character was holding (horribly inefficient of course). After I changed my code to only store a couple Item IDs as ushorts instead of the (up to) 10 character item names, the LoadRawBytes string actually got larger! I even changed several int's into ushort's, but still the save string is bigger.

So, as an exercise, I went through and counted up the bytes I expected to be generated with each new item added to the character. When I add an item to my character, it added 349 new characters to the RawBytes string. However, I'm expecting much less characters based on the code below. I'm counting 2 bytes for each ushort, 4 bytes for each int, and 1 byte for each boolean, and finally not sure how many for the empty custom List or "itemAffixes" objects (assuming <=2?).

Code: Select all

writer.WriteProperty("namePart1", instance.namePart1, ES3Type_ushort.Instance);
writer.WriteProperty("namePart2", instance.namePart2, ES3Type_ushort.Instance);
writer.WriteProperty("itemID", instance.itemID, ES3Type_int.Instance);
writer.WriteProperty("equipped", instance.equipped, ES3Type_bool.Instance);
writer.WriteProperty("level", instance.level, ES3Type_int.Instance);
writer.WriteProperty("characterLevels", instance.characterLevels, ES3Type_int.Instance);
writer.WriteProperty("slot", instance.slot, ES3Type_ushort.Instance);
writer.WriteProperty("iconID", instance.iconID, ES3Type_int.Instance);
writer.WriteProperty("rarity", instance.rarity, ES3Type_ushort.Instance);
writer.WriteProperty("gearScore", instance.gearScore, ES3Type_int.Instance);
writer.WriteProperty("category", instance.category, ES3Type_ushort.Instance);
writer.WriteProperty("uncommonPrefixID", instance.uncommonPrefixID, ES3Type_ushort.Instance);
writer.WriteProperty("rarePrefixID", instance.rarePrefixID, ES3Type_ushort.Instance);
writer.WriteProperty("inventorySlot", instance.inventorySlot, ES3Type_ushort.Instance);
writer.WriteProperty("qty", instance.qty, ES3Type_int.Instance);
writer.WriteProperty("tier", instance.tier, ES3Type_ushort.Instance);
writer.WriteProperty("slotArea", instance.slotArea, ES3Type_ushort.Instance);
writer.WriteProperty("itemAffixes", instance.itemAffixes);
Ultimately, I'm trying to understand 1) Why are so many bytes added, when the data sizes are dramatically less? and 2) Is there any recommendations for crunching down the string generated by LoadRawBytes()?

Re: Save file/string size part deux

Posted: Sun Jun 17, 2018 8:10 am
by Joel
Hi there,

Easy Save 3 saves data in JSON format, which is text-based format. With text-based formats, using a shorter number type such as ushort instead of int will not make a difference in size because the number which is stored to file will still be the same. For example, the text representation of the number 12345 will be 12345 regardless of whether it's a ushort or an int. If it's imperative that you have a compact file size, Easy Save 2 uses binary serialisation, which does get smaller with smaller data types.

If your save file is getting bigger when you're saving less data, this might suggest that you're saving data to additional keys (so there might be redundant keys in your file). If this is the case, deleting the save file should remove them. It could also be that the names of the variables you are using are also longer, as the variable name is also stored to the file. The name of the type is also stored to file, so this might also add length (i.e. the type name System.Int32 is shorter than System.UInt16).

The only other thing I can suggest is that you use shorter property names in your WriteProperty and ReadProperty calls, though this might make your code less maintainable. For example:
writer.WriteProperty("1", instance.namePart1, ES3Type_ushort.Instance);
writer.WriteProperty("2", instance.namePart2, ES3Type_ushort.Instance);
writer.WriteProperty("3", instance.itemID, ES3Type_int.Instance);
// ... etc
case "1":
	instance.namePart1 = reader.Read<ushort>();
	break;
case "2":
	instance.namePart2 = reader.Read<ushort>();
	break;
case "3":
	instance.itemID = reader.Read<int>();
	break;
All the best,
Joel

Re: Save file/string size part deux

Posted: Sun Jun 17, 2018 6:29 pm
by jinxology
Thanks for the info, Joel! That clears up the size thing. I'll see what I can do. Thanks again

Re: Save file/string size part deux

Posted: Tue Jun 19, 2018 10:00 pm
by jinxology
Actually, follow-up question, would it be possible to be using ES3 for most of my project, but to use the ES2 binary serialization only for creating the save string?

Re: Save file/string size part deux

Posted: Wed Jun 20, 2018 7:13 am
by Joel
Hi there,

It's possible to use Easy Save 2 and 3 in your project simultaneously, but you would need to save to different files.

So you would not be able to convert an Easy Save 3 file to binary serialisation because it's a different format.

All the best,
Joel