bigstupidx / protobuf-net

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

Simple performance optimization in TypeModel.SerializeCore #309

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We are building a publisher-subscriber framework on top of Protobuf-Net (great 
work, by the way!) and we are profiling the application to find performance 
issues.

We discovered that 22% of the CPU time spent by the application is in 
TypeModel.GetKey(ref Type), the reason being that the Type<->int map is 
structured as a list, which is then searched linearly. We have 242 types at the 
moment (expecting ~500 in release), and linear search (BasicList.IndexOf) is 
then taking 10% of the total time.

This code path seems to be core to many scenarios, and thus it would probably 
make sense to keep the map in a Dictionary<Type, int> rather than in a list. 
Thoughts?
==============

What version of the product are you using? On what operating system?
We are using ProtobufNet 2.0.0.480 on Windows XP.

Original issue reported on code.google.com by Gabriele.Giuseppini on 2 Aug 2012 at 11:05

GoogleCodeExporter commented 9 years ago
Yes, this is probably something I should look at, especially for large models. 
The naive implementation works fine for small models. Added to the roadmap, 
thanks for the suggestion.

Original comment by marc.gravell on 2 Aug 2012 at 11:59