{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/FileSystem/pulls/comments/82471136","pull_request_review_id":3379530,"id":82471136,"diff_hunk":"@@ -22,12 +41,19 @@ public bool Exists\n \n         public IEnumerator<IFileInfo> GetEnumerator()\n         {\n+            EnsureInitialized();\n             return _entries.GetEnumerator();\n         }\n \n         IEnumerator IEnumerable.GetEnumerator()\n         {\n+            EnsureInitialized();\n             return _entries.GetEnumerator();\n         }\n+\n+        private void EnsureInitialized()\n+        {\n+            LazyInitializer.EnsureInitialized(ref _entries, _entriesFactory);","path":"src/Microsoft.Extensions.FileProviders.Sources/EnumerableDirectoryContents.cs","position":54,"original_position":54,"commit_id":"b3bd5211169b6ebb9af6e7dc9109f658b966de5a","original_commit_id":"b3bd5211169b6ebb9af6e7dc9109f658b966de5a","user":{"login":"pranavkm","id":174281,"avatar_url":"https://avatars.githubusercontent.com/u/174281?v=3","gravatar_id":"","url":"https://api.github.com/users/pranavkm","html_url":"https://github.com/pranavkm","followers_url":"https://api.github.com/users/pranavkm/followers","following_url":"https://api.github.com/users/pranavkm/following{/other_user}","gists_url":"https://api.github.com/users/pranavkm/gists{/gist_id}","starred_url":"https://api.github.com/users/pranavkm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pranavkm/subscriptions","organizations_url":"https://api.github.com/users/pranavkm/orgs","repos_url":"https://api.github.com/users/pranavkm/repos","events_url":"https://api.github.com/users/pranavkm/events{/privacy}","received_events_url":"https://api.github.com/users/pranavkm/received_events","type":"User","site_admin":false},"body":"Probably don't need any of the behavior of `LazyInitializer`. if (_entries == null) { .. }` should suffice.","created_at":"2016-10-07T21:14:10Z","updated_at":"2016-10-07T21:14:16Z","html_url":"https://github.com/aspnet/FileSystem/pull/240#discussion_r82471136","pull_request_url":"https://api.github.com/repos/aspnet/FileSystem/pulls/240","_links":{"self":{"href":"https://api.github.com/repos/aspnet/FileSystem/pulls/comments/82471136"},"html":{"href":"https://github.com/aspnet/FileSystem/pull/240#discussion_r82471136"},"pull_request":{"href":"https://api.github.com/repos/aspnet/FileSystem/pulls/240"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/FileSystem/pulls/240","id":88504548,"html_url":"https://github.com/aspnet/FileSystem/pull/240","diff_url":"https://github.com/aspnet/FileSystem/pull/240.diff","patch_url":"https://github.com/aspnet/FileSystem/pull/240.patch","issue_url":"https://api.github.com/repos/aspnet/FileSystem/issues/240","number":240,"state":"open","locked":false,"title":"Reduce allocations in PhysicalFileProvider when GetDirectoryContents is called but not enumerated","user":{"login":"natemcmaster","id":2696087,"avatar_url":"https://avatars.githubusercontent.com/u/2696087?v=3","gravatar_id":"","url":"https://api.github.com/users/natemcmaster","html_url":"https://github.com/natemcmaster","followers_url":"https://api.github.com/users/natemcmaster/followers","following_url":"https://api.github.com/users/natemcmaster/following{/other_user}","gists_url":"https://api.github.com/users/natemcmaster/gists{/gist_id}","starred_url":"https://api.github.com/users/natemcmaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natemcmaster/subscriptions","organizations_url":"https://api.github.com/users/natemcmaster/orgs","repos_url":"https://api.github.com/users/natemcmaster/repos","events_url":"https://api.github.com/users/natemcmaster/events{/privacy}","received_events_url":"https://api.github.com/users/natemcmaster/received_events","type":"User","site_admin":false},"body":"Resolves #224 \r\n\r\nOptimize PhysicalFileProvider for scenario when it is basically being used for Directory.Exists() (cough, looking at you, aspnet/StaticFiles).\r\n\r\nAdd singleton of NotFoundDirectoryContents.\r\nDelay calling DirectoryInfo.EnumerateFileSystemInfos which does lots of up-front allocation.\r\n\r\n**Benchmark: 100 checks for directory that exists but contents not enumerated**\r\nImportantly, this isn't creating an enumerator. We just want to know if the directory exist.\r\n```c#\r\nbool exists;\r\nfor (var i = 0; i < 100; i++)\r\n{\r\n    var dirContents = provider.GetDirectoryContents(\"exists\");\r\n    exists = dirContents.Exists;\r\n}\r\n```\r\n_Before:_\r\n\r\n![image](https://cloud.githubusercontent.com/assets/2696087/19204640/d267e24a-8c92-11e6-9c51-d3a9b3388ae9.png)\r\n\r\n_After:_\r\n![image](https://cloud.githubusercontent.com/assets/2696087/19204654/ebf7a060-8c92-11e6-8ad7-804fed9eb812.png)\r\n\r\n **Benchmark: 100 checks for directory that **does not exists****\r\n```c#\r\nbool exists;\r\nfor (var i = 0; i < 100; i++)\r\n{\r\n    var dirContents = provider.GetDirectoryContents(\"doesnotexist\");\r\n    exists = dirContents.Exists;\r\n    var e = dirContents.GetEnumerator();\r\n}\r\n```\r\n\r\n_Before:_\r\n![image](https://cloud.githubusercontent.com/assets/2696087/19204393/83c7ab4e-8c91-11e6-8cfd-91fce70c9f6f.png)\r\n\r\n_After:_\r\n![image](https://cloud.githubusercontent.com/assets/2696087/19204502/1fd1c394-8c92-11e6-844d-3aa2889bd67d.png)\r\n\r\n\r\ncc @davidfowl @Tratcher ","created_at":"2016-10-07T20:41:04Z","updated_at":"2016-10-07T21:14:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"be5426e2f222c5c904dde9982c103b9488c3c648","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/FileSystem/pulls/240/commits","review_comments_url":"https://api.github.com/repos/aspnet/FileSystem/pulls/240/comments","review_comment_url":"https://api.github.com/repos/aspnet/FileSystem/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/FileSystem/issues/240/comments","statuses_url":"https://api.github.com/repos/aspnet/FileSystem/statuses/b3bd5211169b6ebb9af6e7dc9109f658b966de5a","head":{"label":"aspnet:namc/less-enumeration","ref":"namc/less-enumeration","sha":"b3bd5211169b6ebb9af6e7dc9109f658b966de5a","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":16161950,"name":"FileSystem","full_name":"aspnet/FileSystem","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/FileSystem","description":"Abstraction of file system APIs.","fork":false,"url":"https://api.github.com/repos/aspnet/FileSystem","forks_url":"https://api.github.com/repos/aspnet/FileSystem/forks","keys_url":"https://api.github.com/repos/aspnet/FileSystem/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/FileSystem/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/FileSystem/teams","hooks_url":"https://api.github.com/repos/aspnet/FileSystem/hooks","issue_events_url":"https://api.github.com/repos/aspnet/FileSystem/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/FileSystem/events","assignees_url":"https://api.github.com/repos/aspnet/FileSystem/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/FileSystem/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/FileSystem/tags","blobs_url":"https://api.github.com/repos/aspnet/FileSystem/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/FileSystem/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/FileSystem/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/FileSystem/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/FileSystem/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/FileSystem/languages","stargazers_url":"https://api.github.com/repos/aspnet/FileSystem/stargazers","contributors_url":"https://api.github.com/repos/aspnet/FileSystem/contributors","subscribers_url":"https://api.github.com/repos/aspnet/FileSystem/subscribers","subscription_url":"https://api.github.com/repos/aspnet/FileSystem/subscription","commits_url":"https://api.github.com/repos/aspnet/FileSystem/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/FileSystem/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/FileSystem/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/FileSystem/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/FileSystem/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/FileSystem/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/FileSystem/merges","archive_url":"https://api.github.com/repos/aspnet/FileSystem/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/FileSystem/downloads","issues_url":"https://api.github.com/repos/aspnet/FileSystem/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/FileSystem/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/FileSystem/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/FileSystem/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/FileSystem/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/FileSystem/releases{/id}","deployments_url":"https://api.github.com/repos/aspnet/FileSystem/deployments","created_at":"2014-01-23T04:09:34Z","updated_at":"2016-10-07T21:04:09Z","pushed_at":"2016-10-07T20:41:04Z","git_url":"git://github.com/aspnet/FileSystem.git","ssh_url":"git@github.com:aspnet/FileSystem.git","clone_url":"https://github.com/aspnet/FileSystem.git","svn_url":"https://github.com/aspnet/FileSystem","homepage":"","size":1222,"stargazers_count":115,"watchers_count":115,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":53,"mirror_url":null,"open_issues_count":36,"forks":53,"open_issues":36,"watchers":115,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"a91165a72bd96ecedd0194107751098645b0d057","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":16161950,"name":"FileSystem","full_name":"aspnet/FileSystem","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/FileSystem","description":"Abstraction of file system APIs.","fork":false,"url":"https://api.github.com/repos/aspnet/FileSystem","forks_url":"https://api.github.com/repos/aspnet/FileSystem/forks","keys_url":"https://api.github.com/repos/aspnet/FileSystem/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/FileSystem/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/FileSystem/teams","hooks_url":"https://api.github.com/repos/aspnet/FileSystem/hooks","issue_events_url":"https://api.github.com/repos/aspnet/FileSystem/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/FileSystem/events","assignees_url":"https://api.github.com/repos/aspnet/FileSystem/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/FileSystem/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/FileSystem/tags","blobs_url":"https://api.github.com/repos/aspnet/FileSystem/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/FileSystem/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/FileSystem/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/FileSystem/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/FileSystem/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/FileSystem/languages","stargazers_url":"https://api.github.com/repos/aspnet/FileSystem/stargazers","contributors_url":"https://api.github.com/repos/aspnet/FileSystem/contributors","subscribers_url":"https://api.github.com/repos/aspnet/FileSystem/subscribers","subscription_url":"https://api.github.com/repos/aspnet/FileSystem/subscription","commits_url":"https://api.github.com/repos/aspnet/FileSystem/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/FileSystem/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/FileSystem/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/FileSystem/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/FileSystem/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/FileSystem/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/FileSystem/merges","archive_url":"https://api.github.com/repos/aspnet/FileSystem/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/FileSystem/downloads","issues_url":"https://api.github.com/repos/aspnet/FileSystem/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/FileSystem/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/FileSystem/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/FileSystem/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/FileSystem/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/FileSystem/releases{/id}","deployments_url":"https://api.github.com/repos/aspnet/FileSystem/deployments","created_at":"2014-01-23T04:09:34Z","updated_at":"2016-10-07T21:04:09Z","pushed_at":"2016-10-07T20:41:04Z","git_url":"git://github.com/aspnet/FileSystem.git","ssh_url":"git@github.com:aspnet/FileSystem.git","clone_url":"https://github.com/aspnet/FileSystem.git","svn_url":"https://github.com/aspnet/FileSystem","homepage":"","size":1222,"stargazers_count":115,"watchers_count":115,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":53,"mirror_url":null,"open_issues_count":36,"forks":53,"open_issues":36,"watchers":115,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/FileSystem/pulls/240"},"html":{"href":"https://github.com/aspnet/FileSystem/pull/240"},"issue":{"href":"https://api.github.com/repos/aspnet/FileSystem/issues/240"},"comments":{"href":"https://api.github.com/repos/aspnet/FileSystem/issues/240/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/FileSystem/pulls/240/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/FileSystem/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/FileSystem/pulls/240/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/FileSystem/statuses/b3bd5211169b6ebb9af6e7dc9109f658b966de5a"}}}}
{"actor":{"display_login":"pranavkm"}}