Mpdreamz/NEST — pull request #366 by Mpdreamz (2013-10-24 12:47:54+00:00)
Title: Profiling

0.11.5.0 had some performance issues with the internal JsonConverters list being a `ConcurrentBag` which has a horrible ToList() performance (DUH! :boom:)

Furthermore thanks to the awesome OSS programs Red Gate have I was able to get a full license to

### Global JsonConverters

Json.NET allows you to register JsonConverters to your serializer and at each position it will ask the registered converters "can you read or write json or shall I do it?" which can be dreadful to performance. I knew this and many commits in the past have been to remove the global registration of converters to attribute based ones so that json.net will only ask the converter(s) for THAT place in the json tree.

Still some global converters sneaked back in, this pull request fixes that by not relying on passing JsonConverters to JsonSerializerSettings at all anymore.

Everything is now part of the ElasticContractResolver (see https://github.com/Mpdreamz/NEST/blob/e99a62b6f5dcdff2b8220ac9804848bd0c40b49b/src/Nest/Resolvers/ElasticContractResolver.cs#L40) which makes the converter part of the cached contract.

Custom JsonConverters you give `ConnectionSettings` also benefit from this cached contract now, albeit with a breaking API change on the `ConnectionSettings`

You can still pass global json converters if you call `client.Serializer.(Des|S)erialize()` though if needs must.

### Reflection caching

Thanks to the profiler I found some places which did not cache reflection properly or were still calling `Activator.CreateInstance` instead of the custom extension method that uses cached compiled lamba expression (much faster) to create instances of types at runtime.