neuecc/ZeroFormatter

Serialize and deserialize the same object increases the size

Closed this issue · 2 comments

I encountered following issue.

I am serializing an object into bytes and write it to the disk. After that I read it, deserialize it, work with it and serialize it again. Each time the file grows until zeroformatter crashes. How can I prevent this?

My guess is, zeroformatter also serializes all the generated properties, but I am not sure.

After several days of testing, my conclusion is, Unions are responsible for this behaviour. I also suspect using "Serializable" with "Zeroformatter" in Attribute declaration causes this or at least affects it. I can only overcome this by removing unions from my data structure. I will close this issue, because no one is interested in solving it, RIP Zeroformatter.

I ran into this issue as well but I was already committed to using Zero Formatter in my project so I came up with a solution that seems to work.

First, I manually have to create a replica object of the original object that I deserialized. Then I copy every field in the old object into the new replica object and then serialize this object instead.

I think this bug has something to do with Zero Formatter trying to keep a history of the object? This really didn't help for lists as it basically increased the total size of the object by the size of serializing all of its fields once for every time you tried serializing the object. Running my serialize/deserialize method on my game's save file 100 times basically brought it up to a 1gig save file.