{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/Mvc/pulls/comments/56581040","id":56581040,"diff_hunk":"@@ -0,0 +1,86 @@\n+﻿// Copyright (c) .NET Foundation. All rights reserved.\n+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.\n+\n+using System;\n+using System.Collections.Concurrent;\n+using System.Collections.Generic;\n+using System.Diagnostics;\n+using System.Linq.Expressions;\n+\n+namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal\n+{\n+    public class ExpressionTextCache\n+    {\n+        public readonly ConcurrentDictionary<LambdaExpression, string> Entries  = \n+                new ConcurrentDictionary<LambdaExpression, string>(LambdaExpressionComparer.Instance);\n+\n+        private class LambdaExpressionComparer : IEqualityComparer<LambdaExpression>\n+        {\n+            public static readonly LambdaExpressionComparer Instance = new LambdaExpressionComparer();\n+\n+            public bool Equals(LambdaExpression lambdaExpression1, LambdaExpression lambdaExpression2)\n+            {\n+                // We will cache only pure member access expressions. Hence we compare two expressions \n+                // to be equal only if they are identical member access expressions.\n+                var expression1 = lambdaExpression1.Body;\n+                var expression2 = lambdaExpression2.Body;\n+\n+                while (expression1 != null && expression2 != null)\n+                {\n+                    if (!expression1.EqualsTo(expression2))\n+                    {\n+                        return false;\n+                    }\n+\n+                    if (expression1.NodeType == ExpressionType.MemberAccess)\n+                    {\n+                        var memberExpression1 = (MemberExpression)expression1;\n+                        expression1 = memberExpression1.Expression;\n+\n+                        var memberExpression2 = (MemberExpression)expression2;\n+                        expression2 = memberExpression2.Expression;\n+                    }\n+                    else if (expression1.NodeType == ExpressionType.Parameter)\n+                    {\n+                        expression1 = expression2 = null;\n+                    }\n+                    else\n+                    {\n+                        // should never come here.\n+                        return false;\n+                    }\n+                }\n+\n+                return true;\n+            }\n+\n+            public int GetHashCode(LambdaExpression lambdaExpression)\n+            {\n+                var expression = lambdaExpression.Body;\n+                var hashCode = 0;\n+\n+                while (expression != null)\n+                {\n+                    if (expression.NodeType == ExpressionType.MemberAccess)\n+                    {\n+                        var memberExpression = (MemberExpression)expression;\n+                        hashCode ^= memberExpression.Member.Name.GetHashCode();\n+                        expression = memberExpression.Expression;\n+                    }\n+                    else if (expression.NodeType == ExpressionType.Parameter)\n+                    {\n+                        var parameterExpression = (ParameterExpression)expression;\n+                        hashCode ^= parameterExpression.Name.GetHashCode();\n+                        expression = null;\n+                    }\n+                    else\n+                    {\n+                        return lambdaExpression.GetHashCode();\n+                    }\n+                }\n+\n+                return hashCode;\n+            }","path":"src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ExpressionTextCache.cs","position":83,"original_position":83,"commit_id":"aef796fc56d133c893328463f881a5826a57feca","original_commit_id":"aef796fc56d133c893328463f881a5826a57feca","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":"Rewrite this method to use `HashCodeCombiner`. You'll see a number of examples in this repo.","created_at":"2016-03-17T21:30:15Z","updated_at":"2016-03-17T21:30:15Z","html_url":"https://github.com/aspnet/Mvc/pull/4298#discussion_r56581040","pull_request_url":"https://api.github.com/repos/aspnet/Mvc/pulls/4298","_links":{"self":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/comments/56581040"},"html":{"href":"https://github.com/aspnet/Mvc/pull/4298#discussion_r56581040"},"pull_request":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/4298"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/Mvc/pulls/4298","id":62996264,"html_url":"https://github.com/aspnet/Mvc/pull/4298","diff_url":"https://github.com/aspnet/Mvc/pull/4298.diff","patch_url":"https://github.com/aspnet/Mvc/pull/4298.patch","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/4298","number":4298,"state":"open","locked":false,"title":"[Perf] Cache Member Access Expression Text to avoid ExpressionHelper.GetExpressionText()","user":{"login":"mnltejaswini","id":8011073,"avatar_url":"https://avatars.githubusercontent.com/u/8011073?v=3","gravatar_id":"","url":"https://api.github.com/users/mnltejaswini","html_url":"https://github.com/mnltejaswini","followers_url":"https://api.github.com/users/mnltejaswini/followers","following_url":"https://api.github.com/users/mnltejaswini/following{/other_user}","gists_url":"https://api.github.com/users/mnltejaswini/gists{/gist_id}","starred_url":"https://api.github.com/users/mnltejaswini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mnltejaswini/subscriptions","organizations_url":"https://api.github.com/users/mnltejaswini/orgs","repos_url":"https://api.github.com/users/mnltejaswini/repos","events_url":"https://api.github.com/users/mnltejaswini/events{/privacy}","received_events_url":"https://api.github.com/users/mnltejaswini/received_events","type":"User","site_admin":false},"body":"Part 1 Fix for  #3921\r\n\r\nBenchmark Test app : https://github.com/aspnet/Performance/tree/dev/testapp/BigViews\r\n\r\nloadtest -k -n 3000 --rps 250  http://localhost:5000\r\n\r\nThere are ~105MB of memory allocations coming from ExpressionHelper.GetExpressionText() which include types of string and stack. For simple lambda expression like member access, the expression text is similar to the expression and doesn't need any kind of evaluations. However, for expressions that include indexer of any kind (variable/constant indexer) we may need additional parsing.  The pull request has changes to cache the expression text for member access expressions. We do not cache the expression text if the expression has indexer. ","created_at":"2016-03-16T00:00:47Z","updated_at":"2016-03-17T21:30:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2f4c2e6991ef5079405a0a56530eeba1ba7b87b6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/Mvc/pulls/4298/commits","review_comments_url":"https://api.github.com/repos/aspnet/Mvc/pulls/4298/comments","review_comment_url":"https://api.github.com/repos/aspnet/Mvc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/4298/comments","statuses_url":"https://api.github.com/repos/aspnet/Mvc/statuses/aef796fc56d133c893328463f881a5826a57feca","head":{"label":"aspnet:naduggar/Issue#3921_1","ref":"naduggar/Issue#3921_1","sha":"aef796fc56d133c893328463f881a5826a57feca","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}","deployments_url":"https://api.github.com/repos/aspnet/Mvc/deployments","created_at":"2013-12-12T03:54:00Z","updated_at":"2016-03-17T13:11:19Z","pushed_at":"2016-03-17T20:41:24Z","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":29497,"stargazers_count":2840,"watchers_count":2840,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1126,"mirror_url":null,"open_issues_count":312,"forks":1126,"open_issues":312,"watchers":2840,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"ec560bdfe0899082ddad15a5edf3cd9b45881e91","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}","deployments_url":"https://api.github.com/repos/aspnet/Mvc/deployments","created_at":"2013-12-12T03:54:00Z","updated_at":"2016-03-17T13:11:19Z","pushed_at":"2016-03-17T20:41:24Z","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":29497,"stargazers_count":2840,"watchers_count":2840,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1126,"mirror_url":null,"open_issues_count":312,"forks":1126,"open_issues":312,"watchers":2840,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/4298"},"html":{"href":"https://github.com/aspnet/Mvc/pull/4298"},"issue":{"href":"https://api.github.com/repos/aspnet/Mvc/issues/4298"},"comments":{"href":"https://api.github.com/repos/aspnet/Mvc/issues/4298/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/4298/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/4298/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/Mvc/statuses/aef796fc56d133c893328463f881a5826a57feca"}}}}