title: Why JsonConvert is Faster than ASP.NET Core's Built-In Json Formatter?
body: <p>I learned that ASP.NET Core uses Newtonsoft.Json 9.0.1 as its built-in JSON formatter (<a href="https://github.com/aspnet/JsonPatch/blob/rel/1.1.0/src/Microsoft.AspNetCore.JsonPatch/project.json#L29" rel="nofollow noreferrer">Microsoft.AspNetCore.JsonPatch</a>). However, I still have not figured out what causes the performance difference between these two codes:</p>
  
  <p><strong>Using Built-In JSON Formatter (Newtonsoft.Json 9.0.1)</strong></p>
  
  <pre><code>[Produces("application/json")]
  [Route("api/BuiltIn")]
  public class BuiltInController : Controller
  {
      private static readonly BufferBlock&lt;ParentModel&gt; Block = new BufferBlock&lt;ParentModel&gt;();
  
      // GET: api/BuiltIn
      [HttpGet]
      public ParentModel Get()
      {
          if (!Block.TryReceive(out ParentModel model)) return null;
          return model;
      }
  
      // POST: api/BuiltIn
      [HttpPost]
      public bool Post([FromBody]ParentModel model)
      {
          if (model == null) return false;
          return Block.Post(model);
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Results (10k requests):</p>
    
    <p>POST - 64 minutes 19 seconds, GET - 57 minutes 8 seconds</p>
  </blockquote>
  
  <p><strong>Using JsonConvert (Newtonsoft.Json 9.0.1 referenced in AspNetCore)</strong></p>
  
  <pre><code>[Produces("application/json")]
  [Route("api/JsonConvert")]
  public class JsonConvertController : Controller
  {
      private static readonly BufferBlock&lt;ParentModel&gt; Block = new BufferBlock&lt;ParentModel&gt;();
  
      // GET: api/JsonConvert
      [HttpGet]
      public ContentResult Get()
      {
          if (!Block.TryReceive(out ParentModel model)) return Content(null);
          return Content(JsonConvert.SerializeObject(model));
      }
  
      // POST: api/JsonConvert
      [HttpPost]
      public bool Post()
      {
          using (var reader = new StreamReader(Request.Body))
          {
              var request = reader.ReadToEnd();
              if (request == null) return false;
              var model = JsonConvert.DeserializeObject&lt;ParentModel&gt;(request);
              return Block.Post(model);
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Results (10k requests):</p>
    
    <p>POST - 63 minutes 47 seconds, GET - 56 minutes 18 seconds</p>
  </blockquote>
  
  <p>No matter how many requests I test, direct use of JsonConvert gives slightly better performance (about 1%). What could be the reason of this performance difference?</p>