Protobuf-net Generics on Unity3D IL2CPP.

When using Protobuf-net in Unity3D, if your Proto-Contracts include generics you might run into a few issues like Unable to resolve MapDecorator constructor.

I had to work with the following contract. It was s custom collection class which had a functionality of caching removed elements in the collection.

[ProtoContract]
public class CustomCollectionBase<TCollection, TElement, TKey{
	[ProtoMember(1)]
	protected TCollection _collection;

	[ProtoMember(2)]
	protected SortedDictionary<TKey, bool_removed;

	public CustomCollectionBase(TCollection collection)
	{
		_collection = collection;
	}
}

[ProtoContract]
public class CustomList<TElement: CustomCollectionBase<List<TElement, TElement, int{
	public CustomList() : base( new List<TElement())
	{
	}
}

[ProtoContract]
public class CustomIntDictionary<TElement: CustomCollectionBase<Dictionary<int, 

JSON vs Protobuf

I did a few tests to compare the data payload sizes of different serialization methods on .NET client server communications.

The test was basically to execute a request/response 20 times.

Request

[Serializable]
[ProtoContract]
public class GetRatingRequest
{
        [ProtoMember(1)]
        public int Rating;
        [ProtoMember(2)]
        public int Count;
        [ProtoMember(3)]
        public float A;
        [ProtoMember(4)]
        public float B;
        [ProtoMember(5)]
        public float C;
        [ProtoMember(6)]
        public float D;
        [ProtoMember(7)]
        public float E;
}

Response

[Serializable]
[ProtoContract]
public class GetRatingResponse
{
        [ProtoMember(1)]
        public List<RatingRatings;
}

[Serializable]
[ProtoContract]
public class Rating
{
        [ProtoMember(1)]
        public bool HighRating { get; set; }
        [ProtoMember(2)]
        public RatingDetail Details { get; set; }
        

Redis .net Tips and Tricks.

  1. Create a Singleton of the Redis connection multiplexer and use it everywhere.
  2. When establishing the connection to the Redis cluster, use a lock on to ensure that multiple threads don’t create the connection concurrently.
  3. Under load of you see that Redis is timing out set ThreadPool.SetMinThreads(…) to around 250 depending on your application. More here – https://docs.microsoft.com/en-us/dotnet/api/system.threading.threadpool.setminthreads?view=netcore-2.0#System_Threading_ThreadPool_SetMinThreads_System_Int32_System_Int32_
  4. If you are executing Lua scripts, ensure that they are performing well using the Redis slow.
  5. If you are running a Redis cluster, ensure that the BGSAVE of each node in the cluster runs at different times. If they run at once, there

C# Dynamic Object Creation Performance

Recently I had to task to create a dynamic object creation factory in C#. So I thought I test all the options I have to check what performs best.

I also wanted to check the performance implications these options have with the number of parameters in the constructor.

The Options

  1. new T() – Using the new/constructor method to
    instantiate objects
  2. Activator.CreateInstance(typeof(T)) – Using the Activator class to instantiate objects
  3. ConstructorInfo.Invoke() – Using the constructor info reflection class to instantiate objects
  4. Func<T>() – Using compiled lambda expressions to instantiate objects

The Test

I ran some tests to see calculate how each …