{"action":"created","comment":{"url":"https://api.github.com/repos/apache/kafka/pulls/comments/45761645","id":45761645,"diff_hunk":"@@ -271,4 +293,33 @@ static public DataInputStream wrapForInput(ByteBufferInputStream buffer, Compres\n             throw new KafkaException(e);\n         }\n     }\n+\n+    private interface ConstructorSupplier {\n+        Constructor get() throws ClassNotFoundException, NoSuchMethodException;\n+    }\n+\n+    // this code is based on Guava's @see{com.google.common.base.Suppliers.MemoizingSupplier}\n+    private static class MemoizingConstructorSupplier {\n+        final ConstructorSupplier delegate;\n+        transient volatile boolean initialized;\n+        transient Constructor value;","path":"clients/src/main/java/org/apache/kafka/common/record/Compressor.java","position":120,"original_position":120,"commit_id":"c2bb4d8ac8448adb50c9a96f117e4e0e01c4e894","original_commit_id":"6c05fbd265cd595e1878d12eb2c1cdc838c80b09","user":{"login":"logarithm","id":427623,"avatar_url":"https://avatars.githubusercontent.com/u/427623?v=3","gravatar_id":"","url":"https://api.github.com/users/logarithm","html_url":"https://github.com/logarithm","followers_url":"https://api.github.com/users/logarithm/followers","following_url":"https://api.github.com/users/logarithm/following{/other_user}","gists_url":"https://api.github.com/users/logarithm/gists{/gist_id}","starred_url":"https://api.github.com/users/logarithm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/logarithm/subscriptions","organizations_url":"https://api.github.com/users/logarithm/orgs","repos_url":"https://api.github.com/users/logarithm/repos","events_url":"https://api.github.com/users/logarithm/events{/privacy}","received_events_url":"https://api.github.com/users/logarithm/received_events","type":"User","site_admin":false},"body":"Yeah, in this particular case we can replace it because value can't be null","created_at":"2015-11-24T16:49:47Z","updated_at":"2015-11-24T16:49:47Z","html_url":"https://github.com/apache/kafka/pull/580#discussion_r45761645","pull_request_url":"https://api.github.com/repos/apache/kafka/pulls/580","_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments/45761645"},"html":{"href":"https://github.com/apache/kafka/pull/580#discussion_r45761645"},"pull_request":{"href":"https://api.github.com/repos/apache/kafka/pulls/580"}}},"pull_request":{"url":"https://api.github.com/repos/apache/kafka/pulls/580","id":51659002,"html_url":"https://github.com/apache/kafka/pull/580","diff_url":"https://github.com/apache/kafka/pull/580.diff","patch_url":"https://github.com/apache/kafka/pull/580.patch","issue_url":"https://api.github.com/repos/apache/kafka/issues/580","number":580,"state":"open","locked":false,"title":"KAFKA-2882: Add constructor cache for Snappy and LZ4 Output/Input streams in Compressor.java","user":{"login":"logarithm","id":427623,"avatar_url":"https://avatars.githubusercontent.com/u/427623?v=3","gravatar_id":"","url":"https://api.github.com/users/logarithm","html_url":"https://github.com/logarithm","followers_url":"https://api.github.com/users/logarithm/followers","following_url":"https://api.github.com/users/logarithm/following{/other_user}","gists_url":"https://api.github.com/users/logarithm/gists{/gist_id}","starred_url":"https://api.github.com/users/logarithm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/logarithm/subscriptions","organizations_url":"https://api.github.com/users/logarithm/orgs","repos_url":"https://api.github.com/users/logarithm/repos","events_url":"https://api.github.com/users/logarithm/events{/privacy}","received_events_url":"https://api.github.com/users/logarithm/received_events","type":"User","site_admin":false},"body":"In `wrapForOutput` and `wrapForInput` methods of `org.apache.kafka.common.record.Compressor`,  `Class.forName(\"[compression codec]\")` and `getConstructor` methods are invoked for each `wrapForOutput` / `wrapForInput` call. Reflection calls are expensive and impact performance at high volumes. This patch adds a cache for `Constructor` to reduce the reflection overhead.\r\n\r\nIn our production deployments, this has reduced producer CPU usage by about 20%","created_at":"2015-11-24T13:26:26Z","updated_at":"2015-11-24T16:49:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"12d3526cc5eea2b87500b3bec815cc190eb51f03","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/kafka/pulls/580/commits","review_comments_url":"https://api.github.com/repos/apache/kafka/pulls/580/comments","review_comment_url":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/kafka/issues/580/comments","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/c2bb4d8ac8448adb50c9a96f117e4e0e01c4e894","head":{"label":"metamx:compressor-getclass-cache","ref":"compressor-getclass-cache","sha":"c2bb4d8ac8448adb50c9a96f117e4e0e01c4e894","user":{"login":"metamx","id":299329,"avatar_url":"https://avatars.githubusercontent.com/u/299329?v=3","gravatar_id":"","url":"https://api.github.com/users/metamx","html_url":"https://github.com/metamx","followers_url":"https://api.github.com/users/metamx/followers","following_url":"https://api.github.com/users/metamx/following{/other_user}","gists_url":"https://api.github.com/users/metamx/gists{/gist_id}","starred_url":"https://api.github.com/users/metamx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metamx/subscriptions","organizations_url":"https://api.github.com/users/metamx/orgs","repos_url":"https://api.github.com/users/metamx/repos","events_url":"https://api.github.com/users/metamx/events{/privacy}","received_events_url":"https://api.github.com/users/metamx/received_events","type":"Organization","site_admin":false},"repo":{"id":46791414,"name":"kafka","full_name":"metamx/kafka","owner":{"login":"metamx","id":299329,"avatar_url":"https://avatars.githubusercontent.com/u/299329?v=3","gravatar_id":"","url":"https://api.github.com/users/metamx","html_url":"https://github.com/metamx","followers_url":"https://api.github.com/users/metamx/followers","following_url":"https://api.github.com/users/metamx/following{/other_user}","gists_url":"https://api.github.com/users/metamx/gists{/gist_id}","starred_url":"https://api.github.com/users/metamx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metamx/subscriptions","organizations_url":"https://api.github.com/users/metamx/orgs","repos_url":"https://api.github.com/users/metamx/repos","events_url":"https://api.github.com/users/metamx/events{/privacy}","received_events_url":"https://api.github.com/users/metamx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/metamx/kafka","description":"Mirror of Apache Kafka","fork":true,"url":"https://api.github.com/repos/metamx/kafka","forks_url":"https://api.github.com/repos/metamx/kafka/forks","keys_url":"https://api.github.com/repos/metamx/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/metamx/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/metamx/kafka/teams","hooks_url":"https://api.github.com/repos/metamx/kafka/hooks","issue_events_url":"https://api.github.com/repos/metamx/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/metamx/kafka/events","assignees_url":"https://api.github.com/repos/metamx/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/metamx/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/metamx/kafka/tags","blobs_url":"https://api.github.com/repos/metamx/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/metamx/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/metamx/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/metamx/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/metamx/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/metamx/kafka/languages","stargazers_url":"https://api.github.com/repos/metamx/kafka/stargazers","contributors_url":"https://api.github.com/repos/metamx/kafka/contributors","subscribers_url":"https://api.github.com/repos/metamx/kafka/subscribers","subscription_url":"https://api.github.com/repos/metamx/kafka/subscription","commits_url":"https://api.github.com/repos/metamx/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/metamx/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/metamx/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/metamx/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/metamx/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/metamx/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/metamx/kafka/merges","archive_url":"https://api.github.com/repos/metamx/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/metamx/kafka/downloads","issues_url":"https://api.github.com/repos/metamx/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/metamx/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/metamx/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/metamx/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/metamx/kafka/labels{/name}","releases_url":"https://api.github.com/repos/metamx/kafka/releases{/id}","created_at":"2015-11-24T12:51:38Z","updated_at":"2015-11-24T12:51:43Z","pushed_at":"2015-11-24T16:47:15Z","git_url":"git://github.com/metamx/kafka.git","ssh_url":"git@github.com:metamx/kafka.git","clone_url":"https://github.com/metamx/kafka.git","svn_url":"https://github.com/metamx/kafka","homepage":null,"size":25530,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"trunk"}},"base":{"label":"apache:trunk","ref":"trunk","sha":"c213952fa180c56908ef70c01a784d24202beb55","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":2211243,"name":"kafka","full_name":"apache/kafka","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/kafka","description":"Mirror of Apache Kafka","fork":false,"url":"https://api.github.com/repos/apache/kafka","forks_url":"https://api.github.com/repos/apache/kafka/forks","keys_url":"https://api.github.com/repos/apache/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/kafka/teams","hooks_url":"https://api.github.com/repos/apache/kafka/hooks","issue_events_url":"https://api.github.com/repos/apache/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/apache/kafka/events","assignees_url":"https://api.github.com/repos/apache/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/apache/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/apache/kafka/tags","blobs_url":"https://api.github.com/repos/apache/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/kafka/languages","stargazers_url":"https://api.github.com/repos/apache/kafka/stargazers","contributors_url":"https://api.github.com/repos/apache/kafka/contributors","subscribers_url":"https://api.github.com/repos/apache/kafka/subscribers","subscription_url":"https://api.github.com/repos/apache/kafka/subscription","commits_url":"https://api.github.com/repos/apache/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/apache/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/kafka/merges","archive_url":"https://api.github.com/repos/apache/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/kafka/downloads","issues_url":"https://api.github.com/repos/apache/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/apache/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/kafka/labels{/name}","releases_url":"https://api.github.com/repos/apache/kafka/releases{/id}","created_at":"2011-08-15T18:06:16Z","updated_at":"2015-11-24T15:00:31Z","pushed_at":"2015-11-24T16:47:17Z","git_url":"git://github.com/apache/kafka.git","ssh_url":"git@github.com:apache/kafka.git","clone_url":"https://github.com/apache/kafka.git","svn_url":"https://github.com/apache/kafka","homepage":null,"size":30497,"stargazers_count":2247,"watchers_count":2247,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1333,"mirror_url":"git://git.apache.org/kafka.git","open_issues_count":109,"forks":1333,"open_issues":109,"watchers":2247,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/580"},"html":{"href":"https://github.com/apache/kafka/pull/580"},"issue":{"href":"https://api.github.com/repos/apache/kafka/issues/580"},"comments":{"href":"https://api.github.com/repos/apache/kafka/issues/580/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/kafka/pulls/580/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/kafka/pulls/580/commits"},"statuses":{"href":"https://api.github.com/repos/apache/kafka/statuses/c2bb4d8ac8448adb50c9a96f117e4e0e01c4e894"}}}}