{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/Mvc/pulls/comments/23191044","id":23191044,"diff_hunk":"@@ -58,93 +64,127 @@ public virtual void CompileViews([NotNull] IBeforeCompileContext context)\n             }\n         }\n \n-        protected virtual IReadOnlyList<RazorFileInfo> CreateCompilationDescriptors(\n-                                                            [NotNull] IBeforeCompileContext context)\n+        protected virtual IEnumerable<RazorFileInfo> CreateCompilationDescriptors(\n+            [NotNull] IBeforeCompileContext context)\n         {\n-            var list = new List<RazorFileInfo>();\n+            var filesToProcess = new List<RelativeFileInfo>();\n+            GetFileInfosRecursive(root: string.Empty, razorFiles: filesToProcess);\n \n-            foreach (var info in GetFileInfosRecursive(string.Empty))\n-            {\n-                var descriptor = ParseView(info, context);\n+            var razorFiles = new RazorFileInfo[filesToProcess.Count];\n+            var syntaxTrees = new SyntaxTree[filesToProcess.Count];\n+            var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = MaxDegreesOfParallelism };\n+            var diagnosticsLock = new object();\n \n-                if (descriptor != null)\n+            Parallel.For(0, filesToProcess.Count, parallelOptions, index =>\n+            {\n+                var file = filesToProcess[index];\n+                var cacheEntry = PreCompilationCache.GetOrSet(file.RelativePath,\n+                                                              file,\n+                                                              OnCacheMiss);\n+                if (cacheEntry != null)\n                 {\n-                    list.Add(descriptor);\n+                    if (cacheEntry.Success)\n+                    {\n+                        syntaxTrees[index] = cacheEntry.SyntaxTree;\n+                        razorFiles[index] = cacheEntry.FileInfo;\n+                    }\n+                    else\n+                    {\n+                        lock (diagnosticsLock)\n+                        {\n+                            foreach (var diagnostic in cacheEntry.Diagnostics)\n+                            {\n+                                context.Diagnostics.Add(diagnostic);\n+                            }\n+                        }\n+                    }\n                 }\n-            }\n+            });\n+\n+            context.CSharpCompilation = context.CSharpCompilation\n+                                               .AddSyntaxTrees(syntaxTrees.Where(tree => tree != null));\n+            return razorFiles.Where(file => file != null);\n+        }\n \n-            return list;\n+        protected IMvcRazorHost GetRazorHost()\n+        {\n+            return _serviceProvider.GetRequiredService<IMvcRazorHost>();\n         }\n \n-        private IEnumerable<RelativeFileInfo> GetFileInfosRecursive(string currentPath)\n+        private PrecompilationCacheEntry OnCacheMiss(ICacheSetContext cacheSetContext)\n         {\n-            var path = currentPath;\n+            var fileInfo = (RelativeFileInfo)cacheSetContext.State;\n+            var entry = GetCacheEntry(fileInfo);\n \n-            var fileInfos = _fileSystem.GetDirectoryContents(path);\n-            if (!fileInfos.Exists)\n+            if (entry != null)\n             {\n-                yield break;\n+                cacheSetContext.AddExpirationTrigger(_fileSystem.Watch(fileInfo.RelativePath));\n+                foreach (var viewStartPath in ViewStartUtility.GetViewStartLocations(fileInfo.RelativePath))\n+                {\n+                    cacheSetContext.AddExpirationTrigger(_fileSystem.Watch(viewStartPath));\n+                }\n             }\n \n+            return entry;\n+        }\n+\n+        private void GetFileInfosRecursive(string root, List<RelativeFileInfo> razorFiles)\n+        {\n+            var fileInfos = _fileSystem.GetDirectoryContents(root);\n+\n             foreach (var fileInfo in fileInfos)\n             {\n                 if (fileInfo.IsDirectory)\n                 {\n-                    var subPath = Path.Combine(path, fileInfo.Name);\n-\n-                    foreach (var info in GetFileInfosRecursive(subPath))\n-                    {\n-                        yield return info;\n-                    }\n+                    var subPath = Path.Combine(root, fileInfo.Name);\n+                    GetFileInfosRecursive(subPath, razorFiles);\n                 }\n                 else if (Path.GetExtension(fileInfo.Name)\n                          .Equals(FileExtension, StringComparison.OrdinalIgnoreCase))\n                 {\n-                    var relativePath = Path.Combine(currentPath, fileInfo.Name);\n+                    var relativePath = Path.Combine(root, fileInfo.Name);\n                     var info = new RelativeFileInfo(fileInfo, relativePath);\n-                    yield return info;\n+                    razorFiles.Add(info);\n                 }\n             }\n         }\n \n-        protected virtual RazorFileInfo ParseView([NotNull] RelativeFileInfo fileInfo,\n-                                                  [NotNull] IBeforeCompileContext context)\n+        protected virtual PrecompilationCacheEntry GetCacheEntry([NotNull] RelativeFileInfo fileInfo)\n         {\n             using (var stream = fileInfo.FileInfo.CreateReadStream())\n             {\n-                var results = _host.GenerateCode(fileInfo.RelativePath, stream);\n+                var host = GetRazorHost();\n+                var results = host.GenerateCode(fileInfo.RelativePath, stream);\n \n-                foreach (var parserError in results.ParserErrors)\n+                if (results.Success)\n                 {\n-                    var diagnostic = parserError.ToDiagnostics(fileInfo.FileInfo.PhysicalPath);\n-                    context.Diagnostics.Add(diagnostic);\n-                }\n-\n-                var generatedCode = results.GeneratedCode;\n-\n-                if (generatedCode != null)\n-                {\n-                    var syntaxTree = SyntaxTreeGenerator.Generate(generatedCode,\n+                    var syntaxTree = SyntaxTreeGenerator.Generate(results.GeneratedCode,\n                                                                   fileInfo.FileInfo.PhysicalPath,\n                                                                   CompilationSettings);\n-                    var fullTypeName = results.GetMainClassName(_host, syntaxTree);\n+                    var fullTypeName = results.GetMainClassName(host, syntaxTree);\n \n                     if (fullTypeName != null)","path":"src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RazorPreCompiler.cs","position":201,"original_position":201,"commit_id":"3122444ba895a8b60f6bd349ea2637954bb7f5bc","original_commit_id":"3122444ba895a8b60f6bd349ea2637954bb7f5bc","user":{"login":"dougbu","id":6431421,"avatar_url":"https://avatars.githubusercontent.com/u/6431421?v=3","gravatar_id":"","url":"https://api.github.com/users/dougbu","html_url":"https://github.com/dougbu","followers_url":"https://api.github.com/users/dougbu/followers","following_url":"https://api.github.com/users/dougbu/following{/other_user}","gists_url":"https://api.github.com/users/dougbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dougbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougbu/subscriptions","organizations_url":"https://api.github.com/users/dougbu/orgs","repos_url":"https://api.github.com/users/dougbu/repos","events_url":"https://api.github.com/users/dougbu/events{/privacy}","received_events_url":"https://api.github.com/users/dougbu/received_events","type":"User","site_admin":false},"body":"how can `fullTypeName` be `null` on the success path?  other code handles `OnCacheEntry()` returning `null` and might be simplified / easier to read if that never happened.  looks like it only happens if `results.Success && fullTypeName == null`.","created_at":"2015-01-19T22:25:18Z","updated_at":"2015-01-19T22:25:18Z","html_url":"https://github.com/aspnet/Mvc/pull/1835#discussion_r23191044","pull_request_url":"https://api.github.com/repos/aspnet/Mvc/pulls/1835","_links":{"self":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/comments/23191044"},"html":{"href":"https://github.com/aspnet/Mvc/pull/1835#discussion_r23191044"},"pull_request":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/1835"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/Mvc/pulls/1835","id":27543198,"html_url":"https://github.com/aspnet/Mvc/pull/1835","diff_url":"https://github.com/aspnet/Mvc/pull/1835.diff","patch_url":"https://github.com/aspnet/Mvc/pull/1835.patch","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/1835","number":1835,"state":"open","locked":false,"title":"* Modifying RazorPrecompiler to use IMemoryCache to cache results when precompilation is invoked via Design Time Host.","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":"* Change compilation to occur in parallel","created_at":"2015-01-16T22:54:27Z","updated_at":"2015-01-19T22:25:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"26d3d133852cf010c25d3e4a1537d0eee02b6979","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/Mvc/pulls/1835/commits","review_comments_url":"https://api.github.com/repos/aspnet/Mvc/pulls/1835/comments","review_comment_url":"https://api.github.com/repos/aspnet/Mvc/pulls/comments/{number}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/1835/comments","statuses_url":"https://api.github.com/repos/aspnet/Mvc/statuses/3122444ba895a8b60f6bd349ea2637954bb7f5bc","head":{"label":"aspnet:PrecompilationOpt","ref":"PrecompilationOpt","sha":"3122444ba895a8b60f6bd349ea2637954bb7f5bc","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":15126429,"name":"Mvc","full_name":"aspnet/Mvc","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/Mvc","description":"Model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor.","fork":false,"url":"https://api.github.com/repos/aspnet/Mvc","forks_url":"https://api.github.com/repos/aspnet/Mvc/forks","keys_url":"https://api.github.com/repos/aspnet/Mvc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Mvc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Mvc/teams","hooks_url":"https://api.github.com/repos/aspnet/Mvc/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Mvc/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Mvc/events","assignees_url":"https://api.github.com/repos/aspnet/Mvc/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Mvc/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Mvc/tags","blobs_url":"https://api.github.com/repos/aspnet/Mvc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Mvc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Mvc/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Mvc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Mvc/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Mvc/languages","stargazers_url":"https://api.github.com/repos/aspnet/Mvc/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Mvc/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Mvc/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Mvc/subscription","commits_url":"https://api.github.com/repos/aspnet/Mvc/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Mvc/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Mvc/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/{number}","contents_url":"https://api.github.com/repos/aspnet/Mvc/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Mvc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Mvc/merges","archive_url":"https://api.github.com/repos/aspnet/Mvc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Mvc/downloads","issues_url":"https://api.github.com/repos/aspnet/Mvc/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Mvc/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Mvc/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Mvc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Mvc/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Mvc/releases{/id}","created_at":"2013-12-12T03:54:00Z","updated_at":"2015-01-19T21:25:45Z","pushed_at":"2015-01-19T22:01:13Z","git_url":"git://github.com/aspnet/Mvc.git","ssh_url":"git@github.com:aspnet/Mvc.git","clone_url":"https://github.com/aspnet/Mvc.git","svn_url":"https://github.com/aspnet/Mvc","homepage":"","size":56762,"stargazers_count":1243,"watchers_count":1243,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":347,"mirror_url":null,"open_issues_count":255,"forks":347,"open_issues":255,"watchers":1243,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"67b078862ee36a846af1b81088e3f2f73f5de3e2","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":15126429,"name":"Mvc","full_name":"aspnet/Mvc","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/Mvc","description":"Model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor.","fork":false,"url":"https://api.github.com/repos/aspnet/Mvc","forks_url":"https://api.github.com/repos/aspnet/Mvc/forks","keys_url":"https://api.github.com/repos/aspnet/Mvc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Mvc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Mvc/teams","hooks_url":"https://api.github.com/repos/aspnet/Mvc/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Mvc/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Mvc/events","assignees_url":"https://api.github.com/repos/aspnet/Mvc/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Mvc/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Mvc/tags","blobs_url":"https://api.github.com/repos/aspnet/Mvc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Mvc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Mvc/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Mvc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Mvc/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Mvc/languages","stargazers_url":"https://api.github.com/repos/aspnet/Mvc/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Mvc/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Mvc/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Mvc/subscription","commits_url":"https://api.github.com/repos/aspnet/Mvc/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Mvc/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Mvc/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/{number}","contents_url":"https://api.github.com/repos/aspnet/Mvc/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Mvc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Mvc/merges","archive_url":"https://api.github.com/repos/aspnet/Mvc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Mvc/downloads","issues_url":"https://api.github.com/repos/aspnet/Mvc/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Mvc/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Mvc/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Mvc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Mvc/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Mvc/releases{/id}","created_at":"2013-12-12T03:54:00Z","updated_at":"2015-01-19T21:25:45Z","pushed_at":"2015-01-19T22:01:13Z","git_url":"git://github.com/aspnet/Mvc.git","ssh_url":"git@github.com:aspnet/Mvc.git","clone_url":"https://github.com/aspnet/Mvc.git","svn_url":"https://github.com/aspnet/Mvc","homepage":"","size":56762,"stargazers_count":1243,"watchers_count":1243,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":347,"mirror_url":null,"open_issues_count":255,"forks":347,"open_issues":255,"watchers":1243,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/1835"},"html":{"href":"https://github.com/aspnet/Mvc/pull/1835"},"issue":{"href":"https://api.github.com/repos/aspnet/Mvc/issues/1835"},"comments":{"href":"https://api.github.com/repos/aspnet/Mvc/issues/1835/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/1835/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/1835/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/Mvc/statuses/3122444ba895a8b60f6bd349ea2637954bb7f5bc"}}}}