I am trying to use ObjectIDGenerator in C # to generate a unique identifier during serialization, however this class is not available in XBox360 or Windows Phone 7.NET frameworks (they use the compact version of .NET). I implemented the version using the Object to Int64 dictionary and was able to get a fully functional version, but the performance is unsatisfactory. I am serializing about tens of thousands of objects, and this is currently the biggest hurdle to save / load. Using the actual .NET implementation on the PC, it takes about 0.3 seconds to serialize about 20,000 objects. Using my implementation, it takes about 6 seconds.
In profiling, I found that the heavy hitters were .TryGetValue and .Add in the dictionary (which makes sense because it indexes and adds a hash map). More importantly, the virtual equality operator was called instead of simply comparing the links, so I implemented IEqualityComparer, which only used ReferenceEquals (this led to an increase in speed).
Does anyone have an understanding of a better implementation of ObjectIDGenerator? Thank you for your help!
My implementation: http://pastebin.com/H1skZwNK
[Change] Another note: profiling results indicate that comparing objects / ReferenceEquals is still a bottleneck, the number of hits is 43,000,000. I wonder if there is a way to store data along this object without having to look for it in the hash map .. .
source share