{"action":"opened","number":1020,"pull_request":{"url":"https://api.github.com/repos/NLog/NLog/pulls/1020","id":50046968,"html_url":"https://github.com/NLog/NLog/pull/1020","diff_url":"https://github.com/NLog/NLog/pull/1020.diff","patch_url":"https://github.com/NLog/NLog/pull/1020.patch","issue_url":"https://api.github.com/repos/NLog/NLog/issues/1020","number":1020,"state":"open","locked":false,"title":"Reduce memory allocations in Logger.Log by avoiding GetEnumerator.","user":{"login":"epignosisx","id":697377,"avatar_url":"https://avatars.githubusercontent.com/u/697377?v=3","gravatar_id":"","url":"https://api.github.com/users/epignosisx","html_url":"https://github.com/epignosisx","followers_url":"https://api.github.com/users/epignosisx/followers","following_url":"https://api.github.com/users/epignosisx/following{/other_user}","gists_url":"https://api.github.com/users/epignosisx/gists{/gist_id}","starred_url":"https://api.github.com/users/epignosisx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epignosisx/subscriptions","organizations_url":"https://api.github.com/users/epignosisx/orgs","repos_url":"https://api.github.com/users/epignosisx/repos","events_url":"https://api.github.com/users/epignosisx/events{/privacy}","received_events_url":"https://api.github.com/users/epignosisx/received_events","type":"User","site_admin":false},"body":"I did some memory profiling on the hot path of Logger.Log method and found there are a few simple optimizations that can be done to avoid memory allocations. This is the app I used to log a message 100,000 times:\r\n\r\n        static void Main(string[] args)\r\n        {\r\n            LogManager.Configuration = CreateConfigurationFromString(@\"\r\n                <nlog>\r\n                    <targets><target name='debug' type='Debug' layout='${message}' /></targets>\r\n                    <rules>\r\n                        <logger name='*' levels='Debug' writeTo='debug'>\r\n                            <filters>\r\n                                <when condition=\"\"length('${message}') > 100\"\" action='Ignore' />\r\n                            </filters>\r\n                        </logger>\r\n                    </rules>\r\n                </nlog>\");\r\n\r\n            var levels = new LogLevel[] { LogLevel.Debug, LogLevel.Info, LogLevel.Warn, LogLevel.Error, LogLevel.Fatal };\r\n\r\n            ILogger logger = LogManager.GetLogger(\"A\");\r\n            logger.Log(levels[0], \"message\");\r\n\r\n            Console.WriteLine(\"Take First snapshot\");\r\n            Console.ReadLine();\r\n            \r\n            for (int i = 0; i < 100000; i++)\r\n            {\r\n                foreach (LogLevel level in levels)\r\n                {\r\n                    logger.Log(level, \"message\");\r\n                }\r\n            }\r\n\r\n            Console.WriteLine(\"Take Last snapshot\");\r\n            Console.ReadLine();\r\n        }\r\n\r\nHere is a screenshot of 3 Enumerator allocations that are targeted in this pull request:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/697377/11017622/e720a5e6-8572-11e5-8b08-57a74c919341.png)\r\n\r\nThese changes remove 4 memory allocations:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/697377/11017647/7750b03e-8573-11e5-83d9-bbbf170270fe.png)\r\n\r\nThe same change can be done to a few more classes:\r\n\r\n- [CsvLayout.GetFormattedMessage](https://github.com/NLog/NLog/blob/master/src/NLog/Layouts/CsvLayout.cs#L174)\r\n- [CsvLayout.GetHeader](https://github.com/NLog/NLog/blob/master/src/NLog/Layouts/CsvLayout.cs#L239)\r\n- [JsonLayout.GetFormattedMessage](https://github.com/NLog/NLog/blob/master/src/NLog/Layouts/JsonLayout.cs#L83)\r\n\r\nI'll submit another pull request with the changes to the classes above if this one is accepted.","created_at":"2015-11-07T22:29:00Z","updated_at":"2015-11-07T22:29:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/NLog/NLog/pulls/1020/commits","review_comments_url":"https://api.github.com/repos/NLog/NLog/pulls/1020/comments","review_comment_url":"https://api.github.com/repos/NLog/NLog/pulls/comments{/number}","comments_url":"https://api.github.com/repos/NLog/NLog/issues/1020/comments","statuses_url":"https://api.github.com/repos/NLog/NLog/statuses/4f07bc6f8b740fff68e9f4c4675abcd6f5d23114","head":{"label":"epignosisx:master","ref":"master","sha":"4f07bc6f8b740fff68e9f4c4675abcd6f5d23114","user":{"login":"epignosisx","id":697377,"avatar_url":"https://avatars.githubusercontent.com/u/697377?v=3","gravatar_id":"","url":"https://api.github.com/users/epignosisx","html_url":"https://github.com/epignosisx","followers_url":"https://api.github.com/users/epignosisx/followers","following_url":"https://api.github.com/users/epignosisx/following{/other_user}","gists_url":"https://api.github.com/users/epignosisx/gists{/gist_id}","starred_url":"https://api.github.com/users/epignosisx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epignosisx/subscriptions","organizations_url":"https://api.github.com/users/epignosisx/orgs","repos_url":"https://api.github.com/users/epignosisx/repos","events_url":"https://api.github.com/users/epignosisx/events{/privacy}","received_events_url":"https://api.github.com/users/epignosisx/received_events","type":"User","site_admin":false},"repo":{"id":45754204,"name":"NLog","full_name":"epignosisx/NLog","owner":{"login":"epignosisx","id":697377,"avatar_url":"https://avatars.githubusercontent.com/u/697377?v=3","gravatar_id":"","url":"https://api.github.com/users/epignosisx","html_url":"https://github.com/epignosisx","followers_url":"https://api.github.com/users/epignosisx/followers","following_url":"https://api.github.com/users/epignosisx/following{/other_user}","gists_url":"https://api.github.com/users/epignosisx/gists{/gist_id}","starred_url":"https://api.github.com/users/epignosisx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epignosisx/subscriptions","organizations_url":"https://api.github.com/users/epignosisx/orgs","repos_url":"https://api.github.com/users/epignosisx/repos","events_url":"https://api.github.com/users/epignosisx/events{/privacy}","received_events_url":"https://api.github.com/users/epignosisx/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/epignosisx/NLog","description":"NLog - Advanced .NET and Silverlight Logging","fork":true,"url":"https://api.github.com/repos/epignosisx/NLog","forks_url":"https://api.github.com/repos/epignosisx/NLog/forks","keys_url":"https://api.github.com/repos/epignosisx/NLog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/epignosisx/NLog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/epignosisx/NLog/teams","hooks_url":"https://api.github.com/repos/epignosisx/NLog/hooks","issue_events_url":"https://api.github.com/repos/epignosisx/NLog/issues/events{/number}","events_url":"https://api.github.com/repos/epignosisx/NLog/events","assignees_url":"https://api.github.com/repos/epignosisx/NLog/assignees{/user}","branches_url":"https://api.github.com/repos/epignosisx/NLog/branches{/branch}","tags_url":"https://api.github.com/repos/epignosisx/NLog/tags","blobs_url":"https://api.github.com/repos/epignosisx/NLog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/epignosisx/NLog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/epignosisx/NLog/git/refs{/sha}","trees_url":"https://api.github.com/repos/epignosisx/NLog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/epignosisx/NLog/statuses/{sha}","languages_url":"https://api.github.com/repos/epignosisx/NLog/languages","stargazers_url":"https://api.github.com/repos/epignosisx/NLog/stargazers","contributors_url":"https://api.github.com/repos/epignosisx/NLog/contributors","subscribers_url":"https://api.github.com/repos/epignosisx/NLog/subscribers","subscription_url":"https://api.github.com/repos/epignosisx/NLog/subscription","commits_url":"https://api.github.com/repos/epignosisx/NLog/commits{/sha}","git_commits_url":"https://api.github.com/repos/epignosisx/NLog/git/commits{/sha}","comments_url":"https://api.github.com/repos/epignosisx/NLog/comments{/number}","issue_comment_url":"https://api.github.com/repos/epignosisx/NLog/issues/comments{/number}","contents_url":"https://api.github.com/repos/epignosisx/NLog/contents/{+path}","compare_url":"https://api.github.com/repos/epignosisx/NLog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/epignosisx/NLog/merges","archive_url":"https://api.github.com/repos/epignosisx/NLog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/epignosisx/NLog/downloads","issues_url":"https://api.github.com/repos/epignosisx/NLog/issues{/number}","pulls_url":"https://api.github.com/repos/epignosisx/NLog/pulls{/number}","milestones_url":"https://api.github.com/repos/epignosisx/NLog/milestones{/number}","notifications_url":"https://api.github.com/repos/epignosisx/NLog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/epignosisx/NLog/labels{/name}","releases_url":"https://api.github.com/repos/epignosisx/NLog/releases{/id}","created_at":"2015-11-07T20:55:06Z","updated_at":"2015-11-07T20:55:11Z","pushed_at":"2015-11-07T21:03:27Z","git_url":"git://github.com/epignosisx/NLog.git","ssh_url":"git@github.com:epignosisx/NLog.git","clone_url":"https://github.com/epignosisx/NLog.git","svn_url":"https://github.com/epignosisx/NLog","homepage":"http://nlog-project.org","size":68095,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"NLog:master","ref":"master","sha":"7f820d5d059497258c68f313c076626d17d39ed6","user":{"login":"NLog","id":2331628,"avatar_url":"https://avatars.githubusercontent.com/u/2331628?v=3","gravatar_id":"","url":"https://api.github.com/users/NLog","html_url":"https://github.com/NLog","followers_url":"https://api.github.com/users/NLog/followers","following_url":"https://api.github.com/users/NLog/following{/other_user}","gists_url":"https://api.github.com/users/NLog/gists{/gist_id}","starred_url":"https://api.github.com/users/NLog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NLog/subscriptions","organizations_url":"https://api.github.com/users/NLog/orgs","repos_url":"https://api.github.com/users/NLog/repos","events_url":"https://api.github.com/users/NLog/events{/privacy}","received_events_url":"https://api.github.com/users/NLog/received_events","type":"Organization","site_admin":false},"repo":{"id":5780416,"name":"NLog","full_name":"NLog/NLog","owner":{"login":"NLog","id":2331628,"avatar_url":"https://avatars.githubusercontent.com/u/2331628?v=3","gravatar_id":"","url":"https://api.github.com/users/NLog","html_url":"https://github.com/NLog","followers_url":"https://api.github.com/users/NLog/followers","following_url":"https://api.github.com/users/NLog/following{/other_user}","gists_url":"https://api.github.com/users/NLog/gists{/gist_id}","starred_url":"https://api.github.com/users/NLog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NLog/subscriptions","organizations_url":"https://api.github.com/users/NLog/orgs","repos_url":"https://api.github.com/users/NLog/repos","events_url":"https://api.github.com/users/NLog/events{/privacy}","received_events_url":"https://api.github.com/users/NLog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NLog/NLog","description":"NLog - Advanced .NET and Silverlight Logging","fork":false,"url":"https://api.github.com/repos/NLog/NLog","forks_url":"https://api.github.com/repos/NLog/NLog/forks","keys_url":"https://api.github.com/repos/NLog/NLog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NLog/NLog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NLog/NLog/teams","hooks_url":"https://api.github.com/repos/NLog/NLog/hooks","issue_events_url":"https://api.github.com/repos/NLog/NLog/issues/events{/number}","events_url":"https://api.github.com/repos/NLog/NLog/events","assignees_url":"https://api.github.com/repos/NLog/NLog/assignees{/user}","branches_url":"https://api.github.com/repos/NLog/NLog/branches{/branch}","tags_url":"https://api.github.com/repos/NLog/NLog/tags","blobs_url":"https://api.github.com/repos/NLog/NLog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NLog/NLog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NLog/NLog/git/refs{/sha}","trees_url":"https://api.github.com/repos/NLog/NLog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NLog/NLog/statuses/{sha}","languages_url":"https://api.github.com/repos/NLog/NLog/languages","stargazers_url":"https://api.github.com/repos/NLog/NLog/stargazers","contributors_url":"https://api.github.com/repos/NLog/NLog/contributors","subscribers_url":"https://api.github.com/repos/NLog/NLog/subscribers","subscription_url":"https://api.github.com/repos/NLog/NLog/subscription","commits_url":"https://api.github.com/repos/NLog/NLog/commits{/sha}","git_commits_url":"https://api.github.com/repos/NLog/NLog/git/commits{/sha}","comments_url":"https://api.github.com/repos/NLog/NLog/comments{/number}","issue_comment_url":"https://api.github.com/repos/NLog/NLog/issues/comments{/number}","contents_url":"https://api.github.com/repos/NLog/NLog/contents/{+path}","compare_url":"https://api.github.com/repos/NLog/NLog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NLog/NLog/merges","archive_url":"https://api.github.com/repos/NLog/NLog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NLog/NLog/downloads","issues_url":"https://api.github.com/repos/NLog/NLog/issues{/number}","pulls_url":"https://api.github.com/repos/NLog/NLog/pulls{/number}","milestones_url":"https://api.github.com/repos/NLog/NLog/milestones{/number}","notifications_url":"https://api.github.com/repos/NLog/NLog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NLog/NLog/labels{/name}","releases_url":"https://api.github.com/repos/NLog/NLog/releases{/id}","created_at":"2012-09-12T13:49:29Z","updated_at":"2015-11-07T04:31:13Z","pushed_at":"2015-11-07T20:34:24Z","git_url":"git://github.com/NLog/NLog.git","ssh_url":"git@github.com:NLog/NLog.git","clone_url":"https://github.com/NLog/NLog.git","svn_url":"https://github.com/NLog/NLog","homepage":"http://nlog-project.org","size":68095,"stargazers_count":1289,"watchers_count":1289,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":474,"mirror_url":null,"open_issues_count":109,"forks":474,"open_issues":109,"watchers":1289,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/NLog/NLog/pulls/1020"},"html":{"href":"https://github.com/NLog/NLog/pull/1020"},"issue":{"href":"https://api.github.com/repos/NLog/NLog/issues/1020"},"comments":{"href":"https://api.github.com/repos/NLog/NLog/issues/1020/comments"},"review_comments":{"href":"https://api.github.com/repos/NLog/NLog/pulls/1020/comments"},"review_comment":{"href":"https://api.github.com/repos/NLog/NLog/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/NLog/NLog/pulls/1020/commits"},"statuses":{"href":"https://api.github.com/repos/NLog/NLog/statuses/4f07bc6f8b740fff68e9f4c4675abcd6f5d23114"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":11,"deletions":7,"changed_files":3}}