Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase deserialization speed?

Serializing/deserializing with BinaryFormatter, resulting serialized file is ~80MB in size. The deserialization takes a few minutes. How could I improve on this? Here's the deserialization code:

    public static Universe DeserializeFromFile(string filepath)
    {
        Universe universe = null;

        FileStream fs = new FileStream(filepath, FileMode.Open);

        BinaryFormatter bf = new BinaryFormatter();
        try
        {
            universe = (Universe)bf.Deserialize(fs);
        }
        catch (SerializationException e)
        {
            Console.WriteLine("Failed to deserialize. Reason: " + e.Message);
            throw;
        }
        finally
        {
            fs.Close();
        }

        return universe;
    }

Maybe read all to memory prior to deserializing or use some other serialization technique?

like image 835
Carlsberg Avatar asked Oct 25 '09 11:10

Carlsberg


1 Answers

Try UnsafeDeserialize. It is said to improve speed.

like image 156
leppie Avatar answered Sep 23 '22 06:09

leppie