{"action":"created","comment":{"url":"https://api.github.com/repos/netty/netty/pulls/comments/28019903","id":28019903,"diff_hunk":"@@ -319,13 +327,86 @@ private int allocateBytesForTree(Http2Stream parent, int connectionWindow) {\n             }\n             connectionWindow = nextConnectionWindow;\n             totalWeight = nextTotalWeight;\n-            tail = nextTail;\n         }\n \n         return bytesAllocated;\n     }\n \n     /**\n+     * Utility class used by the priority algorithm to manage multiple iterations over the children of a given stream.\n+     * This class will try to avoid copying the {@link Collection} returned by the parent {@link\n+     * Http2Stream#children()}} by first iterating over the collection directly. As streams are found that require\n+     * additional processing, they will be added to the next iteration buffer via {@link\n+     * #addToNextIteration(Http2Stream)}. The next call to {@link #iterator()} will return an {@link Iterator} that will\n+     * iterate only over those streams which were added back to the cache.\n+     */\n+    private final class ChildCache implements Iterable<Http2Stream> {\n+        final Collection<? extends Http2Stream> children;\n+        int nextTail;\n+        Http2Stream[] childArray = null;\n+\n+        /**\n+         * Creates the cache and initializes it to iterate over all children of the given parent in the next\n+         * iteration.\n+         */\n+        ChildCache(Http2Stream parent) {\n+            this.children = parent.children();\n+            nextTail = children.size();\n+        }\n+\n+        @Override\n+        @SuppressWarnings(\"unchecked\")\n+        public Iterator<Http2Stream> iterator() {\n+            try {\n+                if (nextTail == 0) {\n+                    // Nothing to iterate over.\n+                    return Collections.emptyIterator();\n+                }\n+\n+                if (childArray != null) {\n+                    // We've allocated the child array, iterate over it up to the specified tail position.\n+                    return Iterators.newIterator(childArray, 0, nextTail);\n+                }\n+\n+                if (nextTail != children.size()) {\n+                    // We should never get here.\n+                    throw new IllegalStateException(\n+                            String.format(\"nextTail (%d) does not match num children (%d)\", nextTail, children.size()));\n+                }\n+\n+                // On the first iteration we use the children collection directly. Future iterations\n+                // will use the childArray.\n+                return (Iterator<Http2Stream>) children.iterator();\n+            } finally {\n+                // Re-initialize the next tail.\n+                nextTail = 0;\n+            }\n+        }\n+\n+        /**\n+         * Adds the given child to the collection iterated over by the next call to {@link #iterator()}.\n+         */\n+        void addToNextIteration(Http2Stream child) {\n+            if (childArray == null) {\n+                // Initial size is 1/4 the number of children.\n+                int initialSize = min(max(4, children.size() / 4), children.size());\n+                childArray = new Http2Stream[initialSize];\n+            } else if (nextTail >= childArray.length) {\n+                // Grow the array by a factor of 2.\n+                childArray = Arrays.copyOf(childArray, min(children.size(), childArray.length * 2));\n+            }\n+            childArray[nextTail++] = child;\n+        }\n+\n+        /**\n+         * Returns the size of the collection to be iterated over by the next call to {@link #iterator()}.\n+         */\n+        int nextIterationSize() {","path":"codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowController.java","position":142,"original_position":142,"commit_id":"e87d6fbff3c2b1fe015e4740b23f8344f3c9a7ad","original_commit_id":"e87d6fbff3c2b1fe015e4740b23f8344f3c9a7ad","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":"make `public`?","created_at":"2015-04-08T22:21:18Z","updated_at":"2015-04-08T22:21:18Z","html_url":"https://github.com/netty/netty/pull/3601#discussion_r28019903","pull_request_url":"https://api.github.com/repos/netty/netty/pulls/3601","_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/comments/28019903"},"html":{"href":"https://github.com/netty/netty/pull/3601#discussion_r28019903"},"pull_request":{"href":"https://api.github.com/repos/netty/netty/pulls/3601"}}},"pull_request":{"url":"https://api.github.com/repos/netty/netty/pulls/3601","id":32904501,"html_url":"https://github.com/netty/netty/pull/3601","diff_url":"https://github.com/netty/netty/pull/3601.diff","patch_url":"https://github.com/netty/netty/pull/3601.patch","issue_url":"https://api.github.com/repos/netty/netty/issues/3601","number":3601,"state":"open","locked":false,"title":"Lazy-copying children in HTTP/2 priority algorithm.","user":{"login":"nmittler","id":6493296,"avatar_url":"https://avatars.githubusercontent.com/u/6493296?v=3","gravatar_id":"","url":"https://api.github.com/users/nmittler","html_url":"https://github.com/nmittler","followers_url":"https://api.github.com/users/nmittler/followers","following_url":"https://api.github.com/users/nmittler/following{/other_user}","gists_url":"https://api.github.com/users/nmittler/gists{/gist_id}","starred_url":"https://api.github.com/users/nmittler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmittler/subscriptions","organizations_url":"https://api.github.com/users/nmittler/orgs","repos_url":"https://api.github.com/users/nmittler/repos","events_url":"https://api.github.com/users/nmittler/events{/privacy}","received_events_url":"https://api.github.com/users/nmittler/received_events","type":"User","site_admin":false},"body":"Motivation:\r\n\r\nWe currently always copy the entire children list into an array. It may not always be necessary to copy any or all of this array.\r\n\r\nModifications:\r\n\r\nModifying the DefaultHttp2RemoteFlowController to lazy copy the children.\r\n\r\nResult:\r\n\r\nFixes #3550","created_at":"2015-04-08T21:33:51Z","updated_at":"2015-04-08T22:21:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ea350125d09fb2b9c60afba2e5beb876ef7f3797","assignee":{"login":"nmittler","id":6493296,"avatar_url":"https://avatars.githubusercontent.com/u/6493296?v=3","gravatar_id":"","url":"https://api.github.com/users/nmittler","html_url":"https://github.com/nmittler","followers_url":"https://api.github.com/users/nmittler/followers","following_url":"https://api.github.com/users/nmittler/following{/other_user}","gists_url":"https://api.github.com/users/nmittler/gists{/gist_id}","starred_url":"https://api.github.com/users/nmittler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmittler/subscriptions","organizations_url":"https://api.github.com/users/nmittler/orgs","repos_url":"https://api.github.com/users/nmittler/repos","events_url":"https://api.github.com/users/nmittler/events{/privacy}","received_events_url":"https://api.github.com/users/nmittler/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/netty/netty/milestones/112","html_url":"https://github.com/netty/netty/milestones/4.1.0.Beta5","labels_url":"https://api.github.com/repos/netty/netty/milestones/112/labels","id":1005380,"number":112,"title":"4.1.0.Beta5","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":70,"closed_issues":53,"state":"open","created_at":"2015-03-04T09:22:23Z","updated_at":"2015-04-08T21:37:12Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/netty/netty/pulls/3601/commits","review_comments_url":"https://api.github.com/repos/netty/netty/pulls/3601/comments","review_comment_url":"https://api.github.com/repos/netty/netty/pulls/comments{/number}","comments_url":"https://api.github.com/repos/netty/netty/issues/3601/comments","statuses_url":"https://api.github.com/repos/netty/netty/statuses/e87d6fbff3c2b1fe015e4740b23f8344f3c9a7ad","head":{"label":"nmittler:lesscopy","ref":"lesscopy","sha":"e87d6fbff3c2b1fe015e4740b23f8344f3c9a7ad","user":{"login":"nmittler","id":6493296,"avatar_url":"https://avatars.githubusercontent.com/u/6493296?v=3","gravatar_id":"","url":"https://api.github.com/users/nmittler","html_url":"https://github.com/nmittler","followers_url":"https://api.github.com/users/nmittler/followers","following_url":"https://api.github.com/users/nmittler/following{/other_user}","gists_url":"https://api.github.com/users/nmittler/gists{/gist_id}","starred_url":"https://api.github.com/users/nmittler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmittler/subscriptions","organizations_url":"https://api.github.com/users/nmittler/orgs","repos_url":"https://api.github.com/users/nmittler/repos","events_url":"https://api.github.com/users/nmittler/events{/privacy}","received_events_url":"https://api.github.com/users/nmittler/received_events","type":"User","site_admin":false},"repo":{"id":18468502,"name":"netty","full_name":"nmittler/netty","owner":{"login":"nmittler","id":6493296,"avatar_url":"https://avatars.githubusercontent.com/u/6493296?v=3","gravatar_id":"","url":"https://api.github.com/users/nmittler","html_url":"https://github.com/nmittler","followers_url":"https://api.github.com/users/nmittler/followers","following_url":"https://api.github.com/users/nmittler/following{/other_user}","gists_url":"https://api.github.com/users/nmittler/gists{/gist_id}","starred_url":"https://api.github.com/users/nmittler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmittler/subscriptions","organizations_url":"https://api.github.com/users/nmittler/orgs","repos_url":"https://api.github.com/users/nmittler/repos","events_url":"https://api.github.com/users/nmittler/events{/privacy}","received_events_url":"https://api.github.com/users/nmittler/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nmittler/netty","description":"Netty project - an event-driven asynchronous network application framework","fork":true,"url":"https://api.github.com/repos/nmittler/netty","forks_url":"https://api.github.com/repos/nmittler/netty/forks","keys_url":"https://api.github.com/repos/nmittler/netty/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nmittler/netty/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nmittler/netty/teams","hooks_url":"https://api.github.com/repos/nmittler/netty/hooks","issue_events_url":"https://api.github.com/repos/nmittler/netty/issues/events{/number}","events_url":"https://api.github.com/repos/nmittler/netty/events","assignees_url":"https://api.github.com/repos/nmittler/netty/assignees{/user}","branches_url":"https://api.github.com/repos/nmittler/netty/branches{/branch}","tags_url":"https://api.github.com/repos/nmittler/netty/tags","blobs_url":"https://api.github.com/repos/nmittler/netty/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nmittler/netty/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nmittler/netty/git/refs{/sha}","trees_url":"https://api.github.com/repos/nmittler/netty/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nmittler/netty/statuses/{sha}","languages_url":"https://api.github.com/repos/nmittler/netty/languages","stargazers_url":"https://api.github.com/repos/nmittler/netty/stargazers","contributors_url":"https://api.github.com/repos/nmittler/netty/contributors","subscribers_url":"https://api.github.com/repos/nmittler/netty/subscribers","subscription_url":"https://api.github.com/repos/nmittler/netty/subscription","commits_url":"https://api.github.com/repos/nmittler/netty/commits{/sha}","git_commits_url":"https://api.github.com/repos/nmittler/netty/git/commits{/sha}","comments_url":"https://api.github.com/repos/nmittler/netty/comments{/number}","issue_comment_url":"https://api.github.com/repos/nmittler/netty/issues/comments{/number}","contents_url":"https://api.github.com/repos/nmittler/netty/contents/{+path}","compare_url":"https://api.github.com/repos/nmittler/netty/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nmittler/netty/merges","archive_url":"https://api.github.com/repos/nmittler/netty/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nmittler/netty/downloads","issues_url":"https://api.github.com/repos/nmittler/netty/issues{/number}","pulls_url":"https://api.github.com/repos/nmittler/netty/pulls{/number}","milestones_url":"https://api.github.com/repos/nmittler/netty/milestones{/number}","notifications_url":"https://api.github.com/repos/nmittler/netty/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nmittler/netty/labels{/name}","releases_url":"https://api.github.com/repos/nmittler/netty/releases{/id}","created_at":"2014-04-05T14:33:03Z","updated_at":"2015-02-02T15:50:48Z","pushed_at":"2015-04-08T21:32:02Z","git_url":"git://github.com/nmittler/netty.git","ssh_url":"git@github.com:nmittler/netty.git","clone_url":"https://github.com/nmittler/netty.git","svn_url":"https://github.com/nmittler/netty","homepage":"http://netty.io/","size":37430,"stargazers_count":0,"watchers_count":0,"language":"Java","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":"netty:master","ref":"master","sha":"30b711cf3d34cd3d2278f21f76ea8a199de0283a","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-04-08T20:48:25Z","pushed_at":"2015-04-08T21:33:51Z","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":114247,"stargazers_count":4385,"watchers_count":4385,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2159,"mirror_url":null,"open_issues_count":259,"forks":2159,"open_issues":259,"watchers":4385,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/3601"},"html":{"href":"https://github.com/netty/netty/pull/3601"},"issue":{"href":"https://api.github.com/repos/netty/netty/issues/3601"},"comments":{"href":"https://api.github.com/repos/netty/netty/issues/3601/comments"},"review_comments":{"href":"https://api.github.com/repos/netty/netty/pulls/3601/comments"},"review_comment":{"href":"https://api.github.com/repos/netty/netty/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/netty/netty/pulls/3601/commits"},"statuses":{"href":"https://api.github.com/repos/netty/netty/statuses/e87d6fbff3c2b1fe015e4740b23f8344f3c9a7ad"}}}}