{"comment":{"url":"https://api.github.com/repos/leonard-thieu/NuTracer/comments/15194627","html_url":"https://github.com/leonard-thieu/NuTracer/commit/de44e78603ac1eab180af4e9998c507cebb269c3#commitcomment-15194627","id":15194627,"user":{"login":"leonard-thieu","id":5265970,"avatar_url":"https://avatars.githubusercontent.com/u/5265970?v=3","gravatar_id":"","url":"https://api.github.com/users/leonard-thieu","html_url":"https://github.com/leonard-thieu","followers_url":"https://api.github.com/users/leonard-thieu/followers","following_url":"https://api.github.com/users/leonard-thieu/following{/other_user}","gists_url":"https://api.github.com/users/leonard-thieu/gists{/gist_id}","starred_url":"https://api.github.com/users/leonard-thieu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leonard-thieu/subscriptions","organizations_url":"https://api.github.com/users/leonard-thieu/orgs","repos_url":"https://api.github.com/users/leonard-thieu/repos","events_url":"https://api.github.com/users/leonard-thieu/events{/privacy}","received_events_url":"https://api.github.com/users/leonard-thieu/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"de44e78603ac1eab180af4e9998c507cebb269c3","created_at":"2015-12-29T19:22:55Z","updated_at":"2015-12-29T19:22:55Z","body":"Improved performance by caching XName objects.\r\n\r\nThe following table lists the time it took to construct the Navigator (10,000,000 iterations) using each method: \r\n\r\nXDocument.Parse | XDocument | XDocument (caching XNames)\r\n---------------------- | --------------- | ---------------------------------------\r\n2m 54s | 0m 23s | 0m 17s\r\n\r\nThe benchmarks were run in LINQPad with the following code: \r\n\r\n##### XDocument.Parse\r\n```csharp\r\nvar isStart = true;\r\nvar displayName = \"activity\";\r\n\r\nfor (int i = 0; i < 10000000; i++)\r\n{\r\n    var xml = XDocument.Parse(string.Format(@\"\r\n         <TraceRecord xmlns='http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord' Severity='{0}'>\r\n             <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier>\r\n             <Description>Activity boundary.</Description>\r\n             <AppDomain>client.vshost.exe</AppDomain>\r\n             <ExtendedData xmlns='http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord'>\r\n                 <ActivityName>{1}</ActivityName>\r\n                 <ActivityType>ActivityTracing</ActivityType>\r\n             </ExtendedData>\r\n         </TraceRecord>\", isStart ? \"Start\" : \"Stop\", displayName)).CreateNavigator();\r\n}\r\n```\r\n\r\n##### XDocument\r\n```csharp\r\nvar isStart = true;\r\nvar displayName = \"activity\";\r\n\r\nvar TraceRecordNamespace = XNamespace.Get(\"http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord\");\r\nvar DictionaryTraceRecordNamespace = XNamespace.Get(\"http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord\");\r\n\r\nfor (int i = 0; i < 10000000; i++)\r\n{\r\n    var xml = (new XDocument(\r\n        new XElement(TraceRecordNamespace + \"TraceRecord\",\r\n            new XAttribute(\"xmlns\", TraceRecordNamespace),\r\n            new XAttribute(\"Severity\", isStart ? \"Start\" : \"Stop\"),\r\n            new XElement(TraceRecordNamespace + \"TraceIdentifier\", \"http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx\"),\r\n            new XElement(TraceRecordNamespace + \"Description\", \"Activity boundary.\"),\r\n            new XElement(TraceRecordNamespace + \"AppDomain\", \"client.vshost.exe\"),\r\n            new XElement(DictionaryTraceRecordNamespace + \"ExtendedData\",\r\n                new XElement(DictionaryTraceRecordNamespace + \"ActivityName\", displayName),\r\n                new XElement(DictionaryTraceRecordNamespace + \"ActivityType\", \"ActivityTracing\")\r\n            )\r\n        )\r\n    )).CreateNavigator();\r\n}\r\n```\r\n\r\n##### XDocument (caching XNames)\r\n```csharp\r\nvar isStart = true;\r\nvar displayName = \"activity\";\r\n\r\nXNamespace TraceRecordNamespace = XNamespace.Get(\"http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord\");\r\nXNamespace DictionaryTraceRecordNamespace = XNamespace.Get(\"http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord\");\r\nvar TraceRecord = TraceRecordNamespace + \"TraceRecord\";\r\nvar TraceIdentifier = TraceRecordNamespace + \"TraceIdentifier\";\r\nvar Description = TraceRecordNamespace + \"Description\";\r\nvar AppDomain = TraceRecordNamespace + \"AppDomain\";\r\nvar ExtendedData = DictionaryTraceRecordNamespace + \"ExtendedData\";\r\nvar ActivityName = DictionaryTraceRecordNamespace + \"ActivityName\";\r\nvar ActivityType = DictionaryTraceRecordNamespace + \"ActivityType\";\r\n\r\nfor (int i = 0; i < 10000000; i++)\r\n{\r\n    var xml = (new XDocument(\r\n        new XElement(TraceRecord,\r\n            new XAttribute(\"xmlns\", TraceRecordNamespace),\r\n            new XAttribute(\"Severity\", isStart ? \"Start\" : \"Stop\"),\r\n            new XElement(TraceIdentifier, \"http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx\"),\r\n            new XElement(Description, \"Activity boundary.\"),\r\n            new XElement(AppDomain, \"client.vshost.exe\"),\r\n            new XElement(ExtendedData,\r\n                new XElement(ActivityName, displayName),\r\n                new XElement(ActivityType, \"ActivityTracing\")\r\n            )\r\n        )\r\n    )).CreateNavigator();\r\n}\r\n```"}}