{"action":"created","issue":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/5197","repository_url":"https://api.github.com/repos/cockroachdb/cockroach","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/5197/labels{/name}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/5197/comments","events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/5197/events","html_url":"https://github.com/cockroachdb/cockroach/pull/5197","id":140411148,"number":5197,"title":"roachpb: Introduce roachpb.Key ShallowNext calls to avoid allocating","user":{"login":"nvanbenschoten","id":5438456,"avatar_url":"https://avatars.githubusercontent.com/u/5438456?v=3","gravatar_id":"","url":"https://api.github.com/users/nvanbenschoten","html_url":"https://github.com/nvanbenschoten","followers_url":"https://api.github.com/users/nvanbenschoten/followers","following_url":"https://api.github.com/users/nvanbenschoten/following{/other_user}","gists_url":"https://api.github.com/users/nvanbenschoten/gists{/gist_id}","starred_url":"https://api.github.com/users/nvanbenschoten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nvanbenschoten/subscriptions","organizations_url":"https://api.github.com/users/nvanbenschoten/orgs","repos_url":"https://api.github.com/users/nvanbenschoten/repos","events_url":"https://api.github.com/users/nvanbenschoten/events{/privacy}","received_events_url":"https://api.github.com/users/nvanbenschoten/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"petermattis","id":6201335,"avatar_url":"https://avatars.githubusercontent.com/u/6201335?v=3","gravatar_id":"","url":"https://api.github.com/users/petermattis","html_url":"https://github.com/petermattis","followers_url":"https://api.github.com/users/petermattis/followers","following_url":"https://api.github.com/users/petermattis/following{/other_user}","gists_url":"https://api.github.com/users/petermattis/gists{/gist_id}","starred_url":"https://api.github.com/users/petermattis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermattis/subscriptions","organizations_url":"https://api.github.com/users/petermattis/orgs","repos_url":"https://api.github.com/users/petermattis/repos","events_url":"https://api.github.com/users/petermattis/events{/privacy}","received_events_url":"https://api.github.com/users/petermattis/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/cockroachdb/cockroach/milestones/1","html_url":"https://github.com/cockroachdb/cockroach/milestones/Beta","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones/1/labels","id":778698,"number":1,"title":"Beta","description":"","creator":{"login":"andybons","id":365204,"avatar_url":"https://avatars.githubusercontent.com/u/365204?v=3","gravatar_id":"","url":"https://api.github.com/users/andybons","html_url":"https://github.com/andybons","followers_url":"https://api.github.com/users/andybons/followers","following_url":"https://api.github.com/users/andybons/following{/other_user}","gists_url":"https://api.github.com/users/andybons/gists{/gist_id}","starred_url":"https://api.github.com/users/andybons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andybons/subscriptions","organizations_url":"https://api.github.com/users/andybons/orgs","repos_url":"https://api.github.com/users/andybons/repos","events_url":"https://api.github.com/users/andybons/events{/privacy}","received_events_url":"https://api.github.com/users/andybons/received_events","type":"User","site_admin":false},"open_issues":109,"closed_issues":386,"state":"open","created_at":"2014-09-04T16:42:18Z","updated_at":"2016-03-12T21:37:33Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2016-03-12T19:48:49Z","updated_at":"2016-03-12T23:08:37Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/5197","html_url":"https://github.com/cockroachdb/cockroach/pull/5197","diff_url":"https://github.com/cockroachdb/cockroach/pull/5197.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/5197.patch"},"body":"Closes #5038.\r\n\r\nIn the majority of the times that we call `Key.Next()`, allocating the\r\nkey and copying is not necessary because neither the current or the\r\nnext key will ever be mutated during their lifetime. This means that it\r\nis safe to share a backing array. Luckily, protobuffer unmarshalling \r\ninto byte slices almost always over-allocates the capacity of\r\nthe slice. This means that in the majority of cases, we have a little\r\nextra slice capacity to play with. This change introduces a `Key.ShallowNext`\r\nmethod that will create the next key in the excess capacity of the\r\nreceiver key if possible, or default to reallocating if needed. It also\r\nuses this new method to replace previous `Key.Next` calls that did not\r\nrequire a deep copy.\r\n\r\nThe second commit here provides a similar treatment to `roachpb.RKey`.\r\n\r\nThe change has minimal impact on cpu performance, but does seem to have\r\na significant impact on the memory behavior of certain workloads.\r\n\r\n```\r\nname                          old alloc/op   new alloc/op   delta\r\nBank_Cockroach-2                61.4kB ± 0%    61.5kB ± 0%     ~           (p=0.469 n=10+10)\r\nSelect1_Cockroach-2             2.28kB ± 0%    2.28kB ± 0%     ~            (p=0.858 n=10+9)\r\nSelect2_Cockroach-2             72.1kB ± 0%    72.2kB ± 0%     ~           (p=0.753 n=10+10)\r\nInsert1_Cockroach-2             23.6kB ± 0%    23.5kB ± 0%   -0.37%        (p=0.001 n=10+10)\r\nInsert10_Cockroach-2            65.1kB ± 0%    64.7kB ± 0%   -0.67%         (p=0.000 n=10+9)\r\nInsert100_Cockroach-2            477kB ± 0%     473kB ± 0%   -0.92%         (p=0.000 n=10+9)\r\nInsert1000_Cockroach-2          4.29MB ± 1%    4.25MB ± 1%   -1.05%         (p=0.000 n=10+9)\r\nUpdate1_Cockroach-2             36.4kB ± 0%    36.3kB ± 0%   -0.21%         (p=0.000 n=9+10)\r\nUpdate10_Cockroach-2             103kB ± 0%     102kB ± 0%   -0.64%         (p=0.000 n=10+8)\r\nUpdate100_Cockroach-2            727kB ± 0%     723kB ± 0%   -0.53%         (p=0.000 n=10+9)\r\nUpdate1000_Cockroach-2          6.34MB ± 1%    6.30MB ± 1%     ~           (p=0.052 n=10+10)\r\nDelete1_Cockroach-2             30.0kB ± 0%    30.0kB ± 0%     ~             (p=0.174 n=9+8)\r\nDelete10_Cockroach-2            72.0kB ± 0%    72.0kB ± 0%     ~            (p=0.604 n=9+10)\r\nDelete100_Cockroach-2            488kB ± 0%     488kB ± 0%     ~             (p=0.863 n=9+9)\r\nDelete1000_Cockroach-2          4.36MB ± 0%    4.36MB ± 0%     ~            (p=0.720 n=9+10)\r\nScan1_Cockroach-2               11.4kB ± 0%    11.4kB ± 0%     ~            (p=0.680 n=10+8)\r\nScan10_Cockroach-2              15.2kB ± 0%    15.2kB ± 0%     ~            (p=0.150 n=10+9)\r\nScan100_Cockroach-2             46.7kB ± 0%    46.7kB ± 0%     ~            (p=0.234 n=10+9)\r\nScan1000_Cockroach-2             327kB ± 0%     327kB ± 0%     ~            (p=0.189 n=9+10)\r\nScan10000_Cockroach-2           5.71MB ± 0%    5.71MB ± 0%     ~           (p=0.796 n=10+10)\r\nScan1000Limit1_Cockroach-2      11.9kB ± 0%    11.9kB ± 0%     ~             (p=0.309 n=9+8)\r\nScan1000Limit10_Cockroach-2     15.6kB ± 0%    15.6kB ± 0%     ~            (p=0.305 n=9+10)\r\nScan1000Limit100_Cockroach-2    47.0kB ± 0%    47.0kB ± 0%     ~           (p=0.381 n=10+10)\r\nPgbenchQuery_Cockroach-2         213kB ± 5%     205kB ± 0%   -4.02%          (p=0.002 n=5+8)\r\n\r\nname                          old allocs/op  new allocs/op  delta\r\nBank_Cockroach-2                 1.43k ± 0%     1.43k ± 0%     ~           (p=0.748 n=10+10)\r\nSelect1_Cockroach-2               50.0 ± 0%      50.0 ± 0%     ~     (all samples are equal)\r\nSelect2_Cockroach-2              2.35k ± 0%     2.35k ± 0%     ~           (p=0.796 n=10+10)\r\nInsert1_Cockroach-2                341 ± 0%       332 ± 0%   -2.69%         (p=0.000 n=9+10)\r\nInsert10_Cockroach-2               782 ± 0%       728 ± 0%   -6.91%          (p=0.000 n=8+7)\r\nInsert100_Cockroach-2            5.07k ± 0%     4.56k ± 0%  -10.06%        (p=0.000 n=10+10)\r\nInsert1000_Cockroach-2           48.0k ± 0%     42.8k ± 0%  -10.70%         (p=0.000 n=10+9)\r\nUpdate1_Cockroach-2                649 ± 0%       640 ± 0%   -1.39%         (p=0.002 n=8+10)\r\nUpdate10_Cockroach-2             1.33k ± 0%     1.27k ± 0%   -4.28%         (p=0.000 n=10+9)\r\nUpdate100_Cockroach-2            7.76k ± 0%     7.26k ± 0%   -6.45%        (p=0.000 n=10+10)\r\nUpdate1000_Cockroach-2           69.2k ± 0%     64.4k ± 0%   -6.92%        (p=0.000 n=10+10)\r\nDelete1_Cockroach-2                529 ± 0%       525 ± 0%   -0.71%          (p=0.000 n=9+7)\r\nDelete10_Cockroach-2             1.12k ± 0%     1.11k ± 0%   -0.36%          (p=0.000 n=9+7)\r\nDelete100_Cockroach-2            6.82k ± 0%     6.81k ± 0%   -0.05%          (p=0.000 n=8+9)\r\nDelete1000_Cockroach-2           63.6k ± 0%     63.6k ± 0%     ~            (p=0.075 n=9+10)\r\nScan1_Cockroach-2                  219 ± 0%       219 ± 0%     ~     (all samples are equal)\r\nScan10_Cockroach-2                 300 ± 0%       299 ± 0%     ~           (p=0.656 n=10+10)\r\nScan100_Cockroach-2              1.03k ± 0%     1.03k ± 0%     ~            (p=0.332 n=10+9)\r\nScan1000_Cockroach-2             8.23k ± 0%     8.23k ± 0%     ~            (p=0.230 n=9+10)\r\nScan10000_Cockroach-2            80.4k ± 0%     80.4k ± 0%     ~           (p=0.636 n=10+10)\r\nScan1000Limit1_Cockroach-2         236 ± 0%       236 ± 0%     ~     (all samples are equal)\r\nScan1000Limit10_Cockroach-2        315 ± 0%       315 ± 0%     ~            (p=0.248 n=9+10)\r\nScan1000Limit100_Cockroach-2     1.04k ± 0%     1.04k ± 0%     ~           (p=1.000 n=10+10)\r\nPgbenchQuery_Cockroach-2         3.60k ± 4%     3.42k ± 0%   -4.84%          (p=0.000 n=5+7)\r\n```\n\n<!-- Reviewable:start -->\n---\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"35\" align=\"absmiddle\" alt=\"Review on Reviewable\"/>](https://reviewable.io/reviews/cockroachdb/cockroach/5197)\n<!-- Reviewable:end -->\n"},"comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments/195823441","html_url":"https://github.com/cockroachdb/cockroach/pull/5197#issuecomment-195823441","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/5197","id":195823441,"user":{"login":"bdarnell","id":160562,"avatar_url":"https://avatars.githubusercontent.com/u/160562?v=3","gravatar_id":"","url":"https://api.github.com/users/bdarnell","html_url":"https://github.com/bdarnell","followers_url":"https://api.github.com/users/bdarnell/followers","following_url":"https://api.github.com/users/bdarnell/following{/other_user}","gists_url":"https://api.github.com/users/bdarnell/gists{/gist_id}","starred_url":"https://api.github.com/users/bdarnell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdarnell/subscriptions","organizations_url":"https://api.github.com/users/bdarnell/orgs","repos_url":"https://api.github.com/users/bdarnell/repos","events_url":"https://api.github.com/users/bdarnell/events{/privacy}","received_events_url":"https://api.github.com/users/bdarnell/received_events","type":"User","site_admin":false},"created_at":"2016-03-12T23:08:37Z","updated_at":"2016-03-12T23:08:37Z","body":"\n\n\n\nReview status: all files reviewed at latest revision, 1 unresolved discussion.\n\n---\n\n*[roachpb/data.go, line 152 \\[r3\\]](https://reviewable.io:443/reviews/cockroachdb/cockroach/5197#-KCh1EGjKc-1Whu7jNw-:-KCh1EGjKc-1Whu7jNw0:305037617) ([raw file](https://github.com/cockroachdb/cockroach/blob/cbf49fb752ee91a96cefa8e848167c3319a8b345/roachpb/data.go#L152)):*\ns/RKey/Key/\n\n---\n\n\n*Comments from the [review on Reviewable.io](https://reviewable.io:443/reviews/cockroachdb/cockroach/5197)*\n<!-- Sent from Reviewable.io -->\n"}}