heweitykc / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

First time Deserialize a Dictionary<DateTime, double>, it took near 400 milliseconds to warmup #277

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
First time Deserialize a Dictionary<DateTime, double>, it took near 400 
milliseconds to warmup. Is there any way to avoid? this result come from the 
Nunit test, if I changed to IIS, will the warmuped protobuf alway in the memory?

I am downloading the latest version protobuf-net r480, for winxp 64 with 
vs2010, .net 4.0.

Here is my code.

Dictionary<DateTime, double> priceHistory = null; (Dictionary<DateTime, 
double>)Cache.Get(cachedKey);
object cachedStream = Cache.Get(cachedKey);
if (cachedStream != null)
{
  using (var fileStream = new MemoryStream((byte[])cachedStream))
  {
     priceHistory = ProtoBuf.Serializer.Deserialize<Dictionary<DateTime, double>>(fileStream);
  }
}

Original issue reported on code.google.com by liangyue...@gmail.com on 14 Mar 2012 at 4:20

GoogleCodeExporter commented 9 years ago
sorry, I used wrong test time area. It should be 127 milliseconds.

Original comment by liangyue...@gmail.com on 14 Mar 2012 at 4:30

GoogleCodeExporter commented 9 years ago
Could you try encapsulating the dictionary? Meaning: instead of serializing a 
dictionary, serialize somethig that *has* a dictionary as a member; example:

    [ProtoMember(1)]
    public class Foo {
       [ProtoMember(1)]
       public Dictionary<your stuff here> Data {get;set;}
    }

Does that improve things?

(sorry cant test myself - not at PC)

Original comment by marc.gravell on 14 Mar 2012 at 4:33

GoogleCodeExporter commented 9 years ago
Thank you very much, Marc. After wraped the dictionary, the warmup time is 
270ms. I tested it many times.

Original comment by liangyue...@gmail.com on 15 Mar 2012 at 10:05