title: Json.Net Compact Framework deserialize performance
body: <p>I am testing the latest build of <a href="http://james.newtonking.com/projects/json-net.aspx" rel="nofollow">Json.Net</a> and I am serializing a collection on the server and passing the string over using a WCF proxy.</p>
  
  <p>The server call takes less than a second to return the data but on the PDA client side the deserialization <code>JsonConvert.DeserializeObject(Of IList(Of BusinessUnitModel))(results)</code> is taking 20-30 seconds.</p>
  
  <p>Is this performance usual with Json.Net or am I doing something wrong with the object or the serialization/deserialization?</p>
  
  <p>I have tried downgrading to a 3.5x version of Json.Net and using the appropriate version on the server and the Compact version on the client but the performance is again poor. </p>
  
  <p><strong>Shared Model</strong></p>
  
  <pre><code>Imports System.ComponentModel.DataAnnotations
  
  Namespace Models
  
      Public Class BusinessUnitModel
          &lt;Required&gt;
          Public Property ID As Int32
          &lt;Required&gt;
          &lt;StringLength(50)&gt;
          Public Property Name As String
          &lt;Required&gt;
          Public Property IsInternalSupplier As Boolean
      End Class
  
  End Namespace
  </code></pre>
  
  <p><strong>Server side serialization</strong></p>
  
  <pre><code>Imports Qsmart.DataProvider.Contracts
  Imports System.ComponentModel.Composition
  Imports Newtonsoft.Json
  
  Namespace Serialiser
  
      &lt;Export(GetType(IModelSerialiser))&gt;
      Public Class JSonSerialiser
          Implements IModelSerialiser
  
          &lt;Import(GetType(ILoggerHelper))&gt;
          Private Property ExHelper As ILoggerHelper
  
          Friend Function Deserailse(Of TModel)(serialised As String) As TModel Implements IModelSerialiser.Deserailse
  
              If serialised Is Nothing Then Throw New ArgumentNullException("serialised")
  
              Try
                  Return JsonConvert.DeserializeObject(serialised)
              Catch ex As JsonSerializationException
                  ExHelper.Process(ex)
                  Throw New ApplicationException("Could Not Deserialse The Model", ex)
              End Try
  
          End Function
  
          Friend Function Serailse(Of TModel)(model As TModel) As String Implements IModelSerialiser.Serailse
  
              If model Is Nothing Then Throw New ArgumentNullException("model")
  
              Try
                  Return JsonConvert.SerializeObject(model)
              Catch ex As JsonSerializationException
                  ExHelper.Process(ex)
                  Throw New ApplicationException("Could Not Serialse The Model", ex)
              End Try
  
          End Function
  
      End Class
  
  End Namespace
  </code></pre>
  
  <p><strong>Server Side Test Data Creation</strong></p>
  
  <pre><code>Public Function QSmartBusinessUnits() As String Implements IQSmartDataProvider.QSmartBusinessUnits
  
      Dim serialsedResult As String = String.Empty
  
      Try
          Dim tester As New List(Of BusinessUnitModel)
          tester.Add(New BusinessUnitModel With {.ID = 1, .Name = "Test1", .IsInternalSupplier = True})
          tester.Add(New BusinessUnitModel With {.ID = 2, .Name = "Test2", .IsInternalSupplier = True})
          tester.Add(New BusinessUnitModel With {.ID = 3, .Name = "Test3", .IsInternalSupplier = True})
          tester.Add(New BusinessUnitModel With {.ID = 4, .Name = "Test4", .IsInternalSupplier = True})
          tester.Add(New BusinessUnitModel With {.ID = 5, .Name = "Test5", .IsInternalSupplier = True})
          tester.Add(New BusinessUnitModel With {.ID = 6, .Name = "Test6", .IsInternalSupplier = True})
  
          serialsedResult = Serialiser.Serailse(tester)
  
      Catch ex As Exception
          ExHelper.Process(ex)
      End Try
  
      Return serialsedResult
  
  End Function
  </code></pre>
  
  <p><strong>Compact Framework Deserialise</strong></p>
  
  <pre><code>Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
      Try
          Dim results As String = _proxy.QSmartBusinessUnits()
          Dim deserialise = JsonConvert.DeserializeObject(Of IList(Of BusinessUnitModel))(results)
          BusinessUnitModelBindingSource.DataSource = deserialise
      Catch ex As Exception
          Stop
      End Try
  
  End Sub
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>If I remove the DataAnnotations from the model the performance is much better, it drops to around 2 seconds... Any idea why this is the case?</p>
  
  <pre><code>Imports System.ComponentModel.DataAnnotations
  
      Namespace Models
  
          Public Class BusinessUnitModel
              Public Property ID As Int32
              Public Property Name As String
              Public Property IsInternalSupplier As Boolean
          End Class
  
      End Namespace
  </code></pre>