Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing large amounts of data in files. What is the most performant option?

Currently doing XML serialization however, it is very slow. Looking for a way to save/load information from file very quickly not really interested in how it looks on disc (if anything I want it to be obscured as I don't want manual editing).

Thinking of binary format however I am not sure if it would be able to serialize properties which may be of a custom type etc.

Any idea's?

like image 375
James Avatar asked Feb 07 '10 22:02

James


3 Answers

You can try using Sqlite. It is very fast, and will give you complete database implementation with SQL queries on a file.

If you are thinking of trying binary formats, I suggest you try this first.

And can be used with ORM, and can be compressed and encrypted.

like image 56
Amirshk Avatar answered Oct 03 '22 21:10

Amirshk


What exactly is the data?

With xml, the obvious answer would be to use smoething like GZipStream to compress it - making it smaller and obscure. You could use BinaryFormatter but it is brittle and IMO unsuitable for long-term storage. I would say "protocol buffers", (maybe protobuf-net), but it depends what the "custom data" is. But if you are using XmlSerializer at the moment protobuf-net may work virtually without changes (maybe add a few attributes) - and it is (in every case I've seen to date) both smaller and faster than BinaryFormatter.

Here's the steep learning curve (see also: Getting Started):

[ProtoContract]
public class Person {
    [ProtoMember(1)]
    public int Id {get;set;}

    [ProtoMember(2)]
    public string Name {get;set;}

    //...
}

To be fair, it can get a little trickier if you are using inheritance - not much though. In many cases you can actually use your existing attributes - it'll work with xml / wcf attributes if an explicit element order is included.

like image 27
Marc Gravell Avatar answered Oct 03 '22 22:10

Marc Gravell


Binary serialization certainly works with properties of Custom Types and typically produces smaller files than XML serialization. It's certainly an approach you should consider if file size is an important factor for your situation.

like image 20
JaredPar Avatar answered Oct 03 '22 21:10

JaredPar