title: Performance Issues when accessing HttpRequestMessage Properties collection in WebAPI
body: <p>Using ASP.NET MVC4 I have created a DelegatingHandler in a WebAPI project. I use the Handler to insert some data into the HttpRequestMessage Properties collection so that later portions of the Http pipeline (e.g. other handlers, controllers) can access that data.</p>
  
  <p>Example:</p>
  
  <pre><code>var httpRequest = (HttpRequestMessageProperty) request.Properties["httpRequest"];
  httpRequest.Headers["MY_DATA"] = "some data";
  </code></pre>
  
  <p>I wanted to test the impact of this on the throughput of WebAPI request processing so I created a console app that, within an Action delegate, instantiates an HttpClient, sends a request, and waits for the response before sending the next one. I count the number of successful executions of this Action delegate within a 5 second window using the performance measurement strategy described here:
  <a href="http://www.codeproject.com/Articles/61964/Performance-Tests-Precise-Run-Time-Measurements-wi" rel="nofollow">http://www.codeproject.com/Articles/61964/Performance-Tests-Precise-Run-Time-Measurements-wi</a></p>
  
  <p>What I have observed is that there is over a magnitude loss in performance in executing the single line that retrieves the httpRequest from the Properties collection.  Without this line of code I see >700 completions within 5 seconds.  When I add that line in, it drops to &lt;20 completions within 5 seconds.</p>
  
  <p>Has anyone else experienced this?  Is there a different method I should use to cache data for the length of a single request that will be available throughout the Http pipeline?</p>