{"action":"created","comment":{"url":"https://api.github.com/repos/netty/netty/pulls/comments/35892692","id":35892692,"diff_hunk":"@@ -1487,31 +1060,58 @@ private HeaderDateFormat() {\n         }\n \n         long parse(String text) throws ParseException {\n-            Date date = dateFormat1.parse(text, parsePos);\n+            Date date = dateFormat1.parse(text);\n             if (date == null) {\n-                date = dateFormat2.parse(text, parsePos);\n+                date = dateFormat2.parse(text);\n             }\n             if (date == null) {\n-                date = dateFormat3.parse(text, parsePos);\n+                date = dateFormat3.parse(text);\n             }\n             if (date == null) {\n                 throw new ParseException(text, 0);\n             }\n             return date.getTime();\n         }\n+    }\n \n-        long parse(String text, long defaultValue) {\n-            Date date = dateFormat1.parse(text, parsePos);\n-            if (date == null) {\n-                date = dateFormat2.parse(text, parsePos);\n-            }\n-            if (date == null) {\n-                date = dateFormat3.parse(text, parsePos);\n+    public interface NameValidator<T> {\n+        void validate(T name);\n+    }\n+\n+    public static final class NoNameValidator<T> implements NameValidator<T> {\n+\n+        @SuppressWarnings(\"rawtypes\")\n+        private static final NameValidator INSTANCE = new NoNameValidator();\n+\n+        private NoNameValidator() {\n+        }\n+\n+        @SuppressWarnings(\"unchecked\")\n+        public static <T> NameValidator<T> instance() {","path":"codec/src/main/java/io/netty/handler/codec/DefaultHeaders.java","position":1275,"original_position":1275,"commit_id":"c06b68575659f738bb0f40b5d7dfc6bd9bd3fb13","original_commit_id":"c06b68575659f738bb0f40b5d7dfc6bd9bd3fb13","user":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"body":"This has changed in #4038...lets re-review there.","created_at":"2015-07-30T16:54:02Z","updated_at":"2015-07-30T16:54:02Z","html_url":"https://github.com/netty/netty/pull/3681#discussion_r35892692","pull_request_url":"https://api.github.com/repos/netty/netty/pulls/3681","_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/comments/35892692"},"html":{"href":"https://github.com/netty/netty/pull/3681#discussion_r35892692"},"pull_request":{"href":"https://api.github.com/repos/netty/netty/pulls/3681"}}},"pull_request":{"url":"https://api.github.com/repos/netty/netty/pulls/3681","id":33792930,"html_url":"https://github.com/netty/netty/pull/3681","diff_url":"https://github.com/netty/netty/pull/3681.diff","patch_url":"https://github.com/netty/netty/pull/3681.patch","issue_url":"https://api.github.com/repos/netty/netty/issues/3681","number":3681,"state":"open","locked":false,"title":"New headers for HTTP, HTTP/2 ...","user":{"login":"buchgr","id":1388179,"avatar_url":"https://avatars.githubusercontent.com/u/1388179?v=3","gravatar_id":"","url":"https://api.github.com/users/buchgr","html_url":"https://github.com/buchgr","followers_url":"https://api.github.com/users/buchgr/followers","following_url":"https://api.github.com/users/buchgr/following{/other_user}","gists_url":"https://api.github.com/users/buchgr/gists{/gist_id}","starred_url":"https://api.github.com/users/buchgr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buchgr/subscriptions","organizations_url":"https://api.github.com/users/buchgr/orgs","repos_url":"https://api.github.com/users/buchgr/repos","events_url":"https://api.github.com/users/buchgr/events{/privacy}","received_events_url":"https://api.github.com/users/buchgr/received_events","type":"User","site_admin":false},"body":"TL;DR;\r\nJust take a look at https://docs.google.com/spreadsheets/d/1ck3RQklyzEcCLlyJoqDXPCWRGVUuS-ArZf0etSXLVDQ/edit#gid=0 for perf comparison.\r\n\r\nMotivation:\r\nWe noticed that the headers implementation in Netty for HTTP/2 uses quite a lot of memory\r\nand that also at least the performance of randomly accessing a header is quite poor. The main\r\nconcern however was memory usage, as profiling has shown that a DefaultHttp2Headers\r\nnot only use a lot of memory it also wastes a lot due to the underlying hashmaps having\r\nto be resized potentially several times as new headers are being inserted.\r\n\r\nThis is tracked as issue #3600.\r\n\r\nModifications:\r\nWe redesigned the DefaultHeaders to simply take a Map object in its constructor and\r\nreimplemented the class using only the Map primitives. That way the implementation\r\nis very concise and hopefully easy to understand and it allows each concrete headers\r\nimplementation to provide its own map or to even use a different headers implementation\r\nfor processing requests and writing responses i.e. incoming headers need to provide\r\nfast random access while outgoing headers need fast insertion and fast iteration. The\r\nnew implementation can support this with hardly any code changes. It also comes\r\nwith the advantage that if the Netty project decides to add a third party collections library\r\nas a dependency, one can simply plug in one of those very fast and memory efficient map\r\nimplementations and get faster and smaller headers for free.\r\n\r\nFor now, we are using the JDK's TreeMap for HTTP and HTTP/2 default headers.\r\n\r\nResult:\r\n\r\n- Significantly fewer lines of code in the implementation. While the total commit is still\r\n  roughly 400 lines less, the actual implementation is a lot less. I just added some more\r\n  tests and microbenchmarks.\r\n\r\n- Overall performance is up. The current implementation should be significantly faster\r\n  for insertion and retrieval. However, it is slower when it comes to iteration. There is simply\r\n  no way a TreeMap can have the same iteration performance as a linked list (as used in the\r\n  current headers implementation). That's totally fine though, because when looking at the\r\n  benchmark results @ejona86 pointed out that the performance of the headers is completely\r\n  dominated by insertion, that is insertion is so significantly faster in the new implementation\r\n  that it does make up for several times the iteration speed. You can't iterate what you haven't\r\n  inserted. I am demonstrating that in this spreadsheet [1]. (Actually, iteration performance is\r\n  only down for HTTP, it's significantly improved for HTTP/2).\r\n\r\n- Memory is down. The implementation with TreeMap uses on avg ~30% less memory. It also does not\r\n  produce any garbage while being resized. In load tests for GRPC we have seen a memory reduction\r\n  of up to 1.2KB per RPC. I summarized the memory improvements in this spreadsheet [1]. The data\r\n  was generated by [2] using JOL.\r\n\r\n- While it was my original intend to only improve the memory usage for HTTP/2, it should be similarly\r\n  improved for HTTP, SPDY and STOMP as they all share a common implementation.\r\n\r\n[1] https://docs.google.com/spreadsheets/d/1ck3RQklyzEcCLlyJoqDXPCWRGVUuS-ArZf0etSXLVDQ/edit#gid=0\r\n[2] https://gist.github.com/buchgr/4458a8bdb51dd58c82b4","created_at":"2015-04-21T19:06:42Z","updated_at":"2015-07-30T16:54:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e096483a3292006d56d07817e8d0e38c39e04698","assignee":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/netty/netty/milestones/117","html_url":"https://github.com/netty/netty/milestones/4.1.0.Beta6","labels_url":"https://api.github.com/repos/netty/netty/milestones/117/labels","id":1100817,"number":117,"title":"4.1.0.Beta6","description":"","creator":{"login":"normanmaurer","id":439362,"avatar_url":"https://avatars.githubusercontent.com/u/439362?v=3","gravatar_id":"","url":"https://api.github.com/users/normanmaurer","html_url":"https://github.com/normanmaurer","followers_url":"https://api.github.com/users/normanmaurer/followers","following_url":"https://api.github.com/users/normanmaurer/following{/other_user}","gists_url":"https://api.github.com/users/normanmaurer/gists{/gist_id}","starred_url":"https://api.github.com/users/normanmaurer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/normanmaurer/subscriptions","organizations_url":"https://api.github.com/users/normanmaurer/orgs","repos_url":"https://api.github.com/users/normanmaurer/repos","events_url":"https://api.github.com/users/normanmaurer/events{/privacy}","received_events_url":"https://api.github.com/users/normanmaurer/received_events","type":"User","site_admin":false},"open_issues":75,"closed_issues":56,"state":"open","created_at":"2015-05-07T19:29:09Z","updated_at":"2015-07-30T07:47:56Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/netty/netty/pulls/3681/commits","review_comments_url":"https://api.github.com/repos/netty/netty/pulls/3681/comments","review_comment_url":"https://api.github.com/repos/netty/netty/pulls/comments{/number}","comments_url":"https://api.github.com/repos/netty/netty/issues/3681/comments","statuses_url":"https://api.github.com/repos/netty/netty/statuses/c06b68575659f738bb0f40b5d7dfc6bd9bd3fb13","head":{"label":"buchgr:newheaders","ref":"newheaders","sha":"c06b68575659f738bb0f40b5d7dfc6bd9bd3fb13","user":{"login":"buchgr","id":1388179,"avatar_url":"https://avatars.githubusercontent.com/u/1388179?v=3","gravatar_id":"","url":"https://api.github.com/users/buchgr","html_url":"https://github.com/buchgr","followers_url":"https://api.github.com/users/buchgr/followers","following_url":"https://api.github.com/users/buchgr/following{/other_user}","gists_url":"https://api.github.com/users/buchgr/gists{/gist_id}","starred_url":"https://api.github.com/users/buchgr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buchgr/subscriptions","organizations_url":"https://api.github.com/users/buchgr/orgs","repos_url":"https://api.github.com/users/buchgr/repos","events_url":"https://api.github.com/users/buchgr/events{/privacy}","received_events_url":"https://api.github.com/users/buchgr/received_events","type":"User","site_admin":false},"repo":{"id":17233219,"name":"netty","full_name":"buchgr/netty","owner":{"login":"buchgr","id":1388179,"avatar_url":"https://avatars.githubusercontent.com/u/1388179?v=3","gravatar_id":"","url":"https://api.github.com/users/buchgr","html_url":"https://github.com/buchgr","followers_url":"https://api.github.com/users/buchgr/followers","following_url":"https://api.github.com/users/buchgr/following{/other_user}","gists_url":"https://api.github.com/users/buchgr/gists{/gist_id}","starred_url":"https://api.github.com/users/buchgr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buchgr/subscriptions","organizations_url":"https://api.github.com/users/buchgr/orgs","repos_url":"https://api.github.com/users/buchgr/repos","events_url":"https://api.github.com/users/buchgr/events{/privacy}","received_events_url":"https://api.github.com/users/buchgr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/buchgr/netty","description":"Netty project - an event-driven asynchronous network application framework","fork":true,"url":"https://api.github.com/repos/buchgr/netty","forks_url":"https://api.github.com/repos/buchgr/netty/forks","keys_url":"https://api.github.com/repos/buchgr/netty/keys{/key_id}","collaborators_url":"https://api.github.com/repos/buchgr/netty/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/buchgr/netty/teams","hooks_url":"https://api.github.com/repos/buchgr/netty/hooks","issue_events_url":"https://api.github.com/repos/buchgr/netty/issues/events{/number}","events_url":"https://api.github.com/repos/buchgr/netty/events","assignees_url":"https://api.github.com/repos/buchgr/netty/assignees{/user}","branches_url":"https://api.github.com/repos/buchgr/netty/branches{/branch}","tags_url":"https://api.github.com/repos/buchgr/netty/tags","blobs_url":"https://api.github.com/repos/buchgr/netty/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/buchgr/netty/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/buchgr/netty/git/refs{/sha}","trees_url":"https://api.github.com/repos/buchgr/netty/git/trees{/sha}","statuses_url":"https://api.github.com/repos/buchgr/netty/statuses/{sha}","languages_url":"https://api.github.com/repos/buchgr/netty/languages","stargazers_url":"https://api.github.com/repos/buchgr/netty/stargazers","contributors_url":"https://api.github.com/repos/buchgr/netty/contributors","subscribers_url":"https://api.github.com/repos/buchgr/netty/subscribers","subscription_url":"https://api.github.com/repos/buchgr/netty/subscription","commits_url":"https://api.github.com/repos/buchgr/netty/commits{/sha}","git_commits_url":"https://api.github.com/repos/buchgr/netty/git/commits{/sha}","comments_url":"https://api.github.com/repos/buchgr/netty/comments{/number}","issue_comment_url":"https://api.github.com/repos/buchgr/netty/issues/comments{/number}","contents_url":"https://api.github.com/repos/buchgr/netty/contents/{+path}","compare_url":"https://api.github.com/repos/buchgr/netty/compare/{base}...{head}","merges_url":"https://api.github.com/repos/buchgr/netty/merges","archive_url":"https://api.github.com/repos/buchgr/netty/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/buchgr/netty/downloads","issues_url":"https://api.github.com/repos/buchgr/netty/issues{/number}","pulls_url":"https://api.github.com/repos/buchgr/netty/pulls{/number}","milestones_url":"https://api.github.com/repos/buchgr/netty/milestones{/number}","notifications_url":"https://api.github.com/repos/buchgr/netty/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/buchgr/netty/labels{/name}","releases_url":"https://api.github.com/repos/buchgr/netty/releases{/id}","created_at":"2014-02-27T02:09:39Z","updated_at":"2015-03-10T20:55:16Z","pushed_at":"2015-07-29T16:43:21Z","git_url":"git://github.com/buchgr/netty.git","ssh_url":"git@github.com:buchgr/netty.git","clone_url":"https://github.com/buchgr/netty.git","svn_url":"https://github.com/buchgr/netty","homepage":"http://netty.io/","size":42240,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":0,"forks":2,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"netty:master","ref":"master","sha":"0f4d6c386efd4dfcae1082d6c095fe46bb9855fe","user":{"login":"netty","id":473791,"avatar_url":"https://avatars.githubusercontent.com/u/473791?v=3","gravatar_id":"","url":"https://api.github.com/users/netty","html_url":"https://github.com/netty","followers_url":"https://api.github.com/users/netty/followers","following_url":"https://api.github.com/users/netty/following{/other_user}","gists_url":"https://api.github.com/users/netty/gists{/gist_id}","starred_url":"https://api.github.com/users/netty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netty/subscriptions","organizations_url":"https://api.github.com/users/netty/orgs","repos_url":"https://api.github.com/users/netty/repos","events_url":"https://api.github.com/users/netty/events{/privacy}","received_events_url":"https://api.github.com/users/netty/received_events","type":"Organization","site_admin":false},"repo":{"id":1064563,"name":"netty","full_name":"netty/netty","owner":{"login":"netty","id":473791,"avatar_url":"https://avatars.githubusercontent.com/u/473791?v=3","gravatar_id":"","url":"https://api.github.com/users/netty","html_url":"https://github.com/netty","followers_url":"https://api.github.com/users/netty/followers","following_url":"https://api.github.com/users/netty/following{/other_user}","gists_url":"https://api.github.com/users/netty/gists{/gist_id}","starred_url":"https://api.github.com/users/netty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netty/subscriptions","organizations_url":"https://api.github.com/users/netty/orgs","repos_url":"https://api.github.com/users/netty/repos","events_url":"https://api.github.com/users/netty/events{/privacy}","received_events_url":"https://api.github.com/users/netty/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/netty/netty","description":"Netty project - an event-driven asynchronous network application framework","fork":false,"url":"https://api.github.com/repos/netty/netty","forks_url":"https://api.github.com/repos/netty/netty/forks","keys_url":"https://api.github.com/repos/netty/netty/keys{/key_id}","collaborators_url":"https://api.github.com/repos/netty/netty/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/netty/netty/teams","hooks_url":"https://api.github.com/repos/netty/netty/hooks","issue_events_url":"https://api.github.com/repos/netty/netty/issues/events{/number}","events_url":"https://api.github.com/repos/netty/netty/events","assignees_url":"https://api.github.com/repos/netty/netty/assignees{/user}","branches_url":"https://api.github.com/repos/netty/netty/branches{/branch}","tags_url":"https://api.github.com/repos/netty/netty/tags","blobs_url":"https://api.github.com/repos/netty/netty/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/netty/netty/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/netty/netty/git/refs{/sha}","trees_url":"https://api.github.com/repos/netty/netty/git/trees{/sha}","statuses_url":"https://api.github.com/repos/netty/netty/statuses/{sha}","languages_url":"https://api.github.com/repos/netty/netty/languages","stargazers_url":"https://api.github.com/repos/netty/netty/stargazers","contributors_url":"https://api.github.com/repos/netty/netty/contributors","subscribers_url":"https://api.github.com/repos/netty/netty/subscribers","subscription_url":"https://api.github.com/repos/netty/netty/subscription","commits_url":"https://api.github.com/repos/netty/netty/commits{/sha}","git_commits_url":"https://api.github.com/repos/netty/netty/git/commits{/sha}","comments_url":"https://api.github.com/repos/netty/netty/comments{/number}","issue_comment_url":"https://api.github.com/repos/netty/netty/issues/comments{/number}","contents_url":"https://api.github.com/repos/netty/netty/contents/{+path}","compare_url":"https://api.github.com/repos/netty/netty/compare/{base}...{head}","merges_url":"https://api.github.com/repos/netty/netty/merges","archive_url":"https://api.github.com/repos/netty/netty/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/netty/netty/downloads","issues_url":"https://api.github.com/repos/netty/netty/issues{/number}","pulls_url":"https://api.github.com/repos/netty/netty/pulls{/number}","milestones_url":"https://api.github.com/repos/netty/netty/milestones{/number}","notifications_url":"https://api.github.com/repos/netty/netty/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/netty/netty/labels{/name}","releases_url":"https://api.github.com/repos/netty/netty/releases{/id}","created_at":"2010-11-09T09:22:21Z","updated_at":"2015-07-30T16:25:36Z","pushed_at":"2015-07-30T10:50:45Z","git_url":"git://github.com/netty/netty.git","ssh_url":"git@github.com:netty/netty.git","clone_url":"https://github.com/netty/netty.git","svn_url":"https://github.com/netty/netty","homepage":"http://netty.io/","size":131749,"stargazers_count":4993,"watchers_count":4993,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2502,"mirror_url":null,"open_issues_count":324,"forks":2502,"open_issues":324,"watchers":4993,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/3681"},"html":{"href":"https://github.com/netty/netty/pull/3681"},"issue":{"href":"https://api.github.com/repos/netty/netty/issues/3681"},"comments":{"href":"https://api.github.com/repos/netty/netty/issues/3681/comments"},"review_comments":{"href":"https://api.github.com/repos/netty/netty/pulls/3681/comments"},"review_comment":{"href":"https://api.github.com/repos/netty/netty/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/netty/netty/pulls/3681/commits"},"statuses":{"href":"https://api.github.com/repos/netty/netty/statuses/c06b68575659f738bb0f40b5d7dfc6bd9bd3fb13"}}}}