From 3c380bc38ede2aa25680e40c02898f954b8a90f6 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Thu, 5 Feb 2015 13:55:09 -0800 Subject: [PATCH] [Perf] #1550 - Turn ModelMetadataProvider into a singleton The modelmetadataprovider does significant reflection caching, which shows up as a hotspot. It's only of our most commonly used services, so not only do a TON of instances get created, they are very heavy-weight because of the two ConcurrentDictionary instances they have. --- src/Microsoft.AspNet.Mvc/MvcServices.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Mvc/MvcServices.cs b/src/Microsoft.AspNet.Mvc/MvcServices.cs index 114fba6b45..49a247c7ec 100644 --- a/src/Microsoft.AspNet.Mvc/MvcServices.cs +++ b/src/Microsoft.AspNet.Mvc/MvcServices.cs @@ -79,7 +79,9 @@ namespace Microsoft.AspNet.Mvc // Dataflow - ModelBinding, Validation and Formatting - yield return describe.Transient(); + // The DataAnnotationsModelMetadataProvider does significant caching of reflection/attributes + // and thus needs to be singleton. + yield return describe.Singleton(); yield return describe.Transient(); yield return describe.Scoped();