{"action":"created","comment":{"url":"https://api.github.com/repos/mostjs/core/pulls/comments/185967073","pull_request_review_id":117467325,"id":185967073,"diff_hunk":"@@ -1,64 +1,98 @@\n-/** @license MIT License (c) copyright 2010-2016 original author or authors */\n-/** @author Brian Cavalier */\n-/** @author John Hann */\n+/** @license MIT License (c) copyright 2010 original author or authors */\n \n-// Based on https://github.com/petkaantonov/deque\n+// Based on https://github.com/invertase/denque\n \n export default class Queue {\n-  constructor (capPow2 = 32) {\n-    this._capacity = capPow2\n-    this._length = 0\n+  constructor () {\n     this._head = 0\n+    this._tail = 0\n+    this._capacityMask = 0x3\n+    this._list = new Array(4)\n   }\n \n   push (x) {\n-    const len = this._length\n-    this._checkCapacity(len + 1)\n+    const tail = this._tail\n+    this._list[tail] = x\n+    this._tail = (tail + 1) & this._capacityMask\n+    if (this._tail === this._head) {\n+      this._growArray()\n+    }\n \n-    const i = (this._head + len) & (this._capacity - 1)\n-    this[i] = x\n-    this._length = len + 1\n+    if (this._head < this._tail) {\n+      return this._tail - this._head\n+    } else {\n+      return this._capacityMask + 1 - (this._head - this._tail)\n+    }\n   }\n \n   shift () {\n     const head = this._head\n-    const x = this[head]\n+    if (head === this._tail) {\n+      return undefined\n+    }\n+\n+    const x = this._list[head]\n+    this._list[head] = undefined\n+    this._head = (head + 1) & this._capacityMask\n+    if (head < 2 && this._tail > 10000 && this._tail <= this._list.length >>> 2) {\n+      this._shrinkArray()\n+    }\n \n-    this[head] = void 0\n-    this._head = (head + 1) & (this._capacity - 1)\n-    this._length--\n     return x\n   }\n \n   isEmpty () {\n-    return this._length === 0\n+    return this._head === this._tail\n   }\n \n   length () {\n-    return this._length\n+    if (this._head === this._tail) {\n+      return 0\n+    } else if (this._head < this._tail) {\n+      return this._tail - this._head\n+    } else {\n+      return this._capacityMask + 1 - (this._head - this._tail)\n+    }\n   }\n \n-  _checkCapacity (size) {\n-    if (this._capacity < size) {\n-      this._ensureCapacity(this._capacity << 1)\n+  _growArray () {\n+    if (this._head) {\n+      // copy existing data, head to end, then beginning to tail.\n+      this._list = this._copyArray(true)\n+      this._head = 0\n     }\n+\n+    // head is at 0 and array is now full, safe to extend\n+    this._tail = this._list.length\n+\n+    this._list.length *= 2\n+    this._capacityMask = (this._capacityMask << 1) | 1\n   }\n \n-  _ensureCapacity (capacity) {\n-    const oldCapacity = this._capacity\n-    this._capacity = capacity\n+  _shrinkArray () {\n+    this._list.length >>>= 1\n+    this._capacityMask >>>= 1\n+  }\n \n-    const last = this._head + this._length\n+  _copyArray (fullCopy) {","path":"packages/core/src/Queue.js","position":102,"original_position":102,"commit_id":"1685078eb2c627bc31649a37ab93516170cf25ef","original_commit_id":"1685078eb2c627bc31649a37ab93516170cf25ef","user":{"login":"Frikki","id":180569,"avatar_url":"https://avatars2.githubusercontent.com/u/180569?v=4","gravatar_id":"","url":"https://api.github.com/users/Frikki","html_url":"https://github.com/Frikki","followers_url":"https://api.github.com/users/Frikki/followers","following_url":"https://api.github.com/users/Frikki/following{/other_user}","gists_url":"https://api.github.com/users/Frikki/gists{/gist_id}","starred_url":"https://api.github.com/users/Frikki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Frikki/subscriptions","organizations_url":"https://api.github.com/users/Frikki/orgs","repos_url":"https://api.github.com/users/Frikki/repos","events_url":"https://api.github.com/users/Frikki/events{/privacy}","received_events_url":"https://api.github.com/users/Frikki/received_events","type":"User","site_admin":false},"body":"In relation to this comment, https://github.com/mostjs/core/pull/235#discussion_r185966918, I also think we should optimize this function.","created_at":"2018-05-04T00:00:38Z","updated_at":"2018-05-04T00:00:38Z","html_url":"https://github.com/mostjs/core/pull/235#discussion_r185967073","pull_request_url":"https://api.github.com/repos/mostjs/core/pulls/235","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/mostjs/core/pulls/comments/185967073"},"html":{"href":"https://github.com/mostjs/core/pull/235#discussion_r185967073"},"pull_request":{"href":"https://api.github.com/repos/mostjs/core/pulls/235"}},"in_reply_to_id":184538393},"pull_request":{"url":"https://api.github.com/repos/mostjs/core/pulls/235","id":183411386,"html_url":"https://github.com/mostjs/core/pull/235","diff_url":"https://github.com/mostjs/core/pull/235.diff","patch_url":"https://github.com/mostjs/core/pull/235.patch","issue_url":"https://api.github.com/repos/mostjs/core/issues/235","number":235,"state":"open","locked":false,"title":"Use denque-based Queue","user":{"login":"briancavalier","id":90518,"avatar_url":"https://avatars2.githubusercontent.com/u/90518?v=4","gravatar_id":"","url":"https://api.github.com/users/briancavalier","html_url":"https://github.com/briancavalier","followers_url":"https://api.github.com/users/briancavalier/followers","following_url":"https://api.github.com/users/briancavalier/following{/other_user}","gists_url":"https://api.github.com/users/briancavalier/gists{/gist_id}","starred_url":"https://api.github.com/users/briancavalier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/briancavalier/subscriptions","organizations_url":"https://api.github.com/users/briancavalier/orgs","repos_url":"https://api.github.com/users/briancavalier/repos","events_url":"https://api.github.com/users/briancavalier/events{/privacy}","received_events_url":"https://api.github.com/users/briancavalier/received_events","type":"User","site_admin":false},"body":"Update Queue to be based on [denque](https://github.com/invertase/denque) rather than [deque](https://github.com/petkaantonov/deque).  Apparently, denque is an updated approach that performs better on newer engines.\r\n\r\nHere's a representative result:\r\n\r\n```\r\n❯ babel-node --presets env ./zip.js\r\nzip 2 x 100000 integers\r\n-------------------------------------------------------\r\nmost                118.98 op/s ±  0.87%   (71 samples)\r\n\r\n~/Projects/cujojs/@most/core/packages/core/test/perf use-denque-zip* 3m 25s\r\n❯ babel-node --presets env ./zip.js\r\nzip 2 x 100000 integers\r\n-------------------------------------------------------\r\nmost                135.29 op/s ±  0.53%   (72 samples)\r\n```\r\n\r\nI've run it numerous times, and the difference is consistently around 15%.  There's a small difference in library size, but unless you're actually using `zip` (or zipArray), Queue will be tree-shaken, so you won't notice.\r\n\r\nI also updated the perf tests to get the all running again.","created_at":"2018-04-23T12:00:50Z","updated_at":"2018-05-04T00:00:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eea721c598066db50ea4f2546971ef65fe87bcd3","assignee":null,"assignees":[],"requested_reviewers":[{"login":"TylorS","id":6282473,"avatar_url":"https://avatars3.githubusercontent.com/u/6282473?v=4","gravatar_id":"","url":"https://api.github.com/users/TylorS","html_url":"https://github.com/TylorS","followers_url":"https://api.github.com/users/TylorS/followers","following_url":"https://api.github.com/users/TylorS/following{/other_user}","gists_url":"https://api.github.com/users/TylorS/gists{/gist_id}","starred_url":"https://api.github.com/users/TylorS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TylorS/subscriptions","organizations_url":"https://api.github.com/users/TylorS/orgs","repos_url":"https://api.github.com/users/TylorS/repos","events_url":"https://api.github.com/users/TylorS/events{/privacy}","received_events_url":"https://api.github.com/users/TylorS/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/mostjs/core/pulls/235/commits","review_comments_url":"https://api.github.com/repos/mostjs/core/pulls/235/comments","review_comment_url":"https://api.github.com/repos/mostjs/core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mostjs/core/issues/235/comments","statuses_url":"https://api.github.com/repos/mostjs/core/statuses/1685078eb2c627bc31649a37ab93516170cf25ef","head":{"label":"mostjs:use-denque-zip","ref":"use-denque-zip","sha":"1685078eb2c627bc31649a37ab93516170cf25ef","user":{"login":"mostjs","id":15834413,"avatar_url":"https://avatars0.githubusercontent.com/u/15834413?v=4","gravatar_id":"","url":"https://api.github.com/users/mostjs","html_url":"https://github.com/mostjs","followers_url":"https://api.github.com/users/mostjs/followers","following_url":"https://api.github.com/users/mostjs/following{/other_user}","gists_url":"https://api.github.com/users/mostjs/gists{/gist_id}","starred_url":"https://api.github.com/users/mostjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mostjs/subscriptions","organizations_url":"https://api.github.com/users/mostjs/orgs","repos_url":"https://api.github.com/users/mostjs/repos","events_url":"https://api.github.com/users/mostjs/events{/privacy}","received_events_url":"https://api.github.com/users/mostjs/received_events","type":"Organization","site_admin":false},"repo":{"id":77230382,"name":"core","full_name":"mostjs/core","owner":{"login":"mostjs","id":15834413,"avatar_url":"https://avatars0.githubusercontent.com/u/15834413?v=4","gravatar_id":"","url":"https://api.github.com/users/mostjs","html_url":"https://github.com/mostjs","followers_url":"https://api.github.com/users/mostjs/followers","following_url":"https://api.github.com/users/mostjs/following{/other_user}","gists_url":"https://api.github.com/users/mostjs/gists{/gist_id}","starred_url":"https://api.github.com/users/mostjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mostjs/subscriptions","organizations_url":"https://api.github.com/users/mostjs/orgs","repos_url":"https://api.github.com/users/mostjs/repos","events_url":"https://api.github.com/users/mostjs/events{/privacy}","received_events_url":"https://api.github.com/users/mostjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mostjs/core","description":"Most.js core event stream","fork":false,"url":"https://api.github.com/repos/mostjs/core","forks_url":"https://api.github.com/repos/mostjs/core/forks","keys_url":"https://api.github.com/repos/mostjs/core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mostjs/core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mostjs/core/teams","hooks_url":"https://api.github.com/repos/mostjs/core/hooks","issue_events_url":"https://api.github.com/repos/mostjs/core/issues/events{/number}","events_url":"https://api.github.com/repos/mostjs/core/events","assignees_url":"https://api.github.com/repos/mostjs/core/assignees{/user}","branches_url":"https://api.github.com/repos/mostjs/core/branches{/branch}","tags_url":"https://api.github.com/repos/mostjs/core/tags","blobs_url":"https://api.github.com/repos/mostjs/core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mostjs/core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mostjs/core/git/refs{/sha}","trees_url":"https://api.github.com/repos/mostjs/core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mostjs/core/statuses/{sha}","languages_url":"https://api.github.com/repos/mostjs/core/languages","stargazers_url":"https://api.github.com/repos/mostjs/core/stargazers","contributors_url":"https://api.github.com/repos/mostjs/core/contributors","subscribers_url":"https://api.github.com/repos/mostjs/core/subscribers","subscription_url":"https://api.github.com/repos/mostjs/core/subscription","commits_url":"https://api.github.com/repos/mostjs/core/commits{/sha}","git_commits_url":"https://api.github.com/repos/mostjs/core/git/commits{/sha}","comments_url":"https://api.github.com/repos/mostjs/core/comments{/number}","issue_comment_url":"https://api.github.com/repos/mostjs/core/issues/comments{/number}","contents_url":"https://api.github.com/repos/mostjs/core/contents/{+path}","compare_url":"https://api.github.com/repos/mostjs/core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mostjs/core/merges","archive_url":"https://api.github.com/repos/mostjs/core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mostjs/core/downloads","issues_url":"https://api.github.com/repos/mostjs/core/issues{/number}","pulls_url":"https://api.github.com/repos/mostjs/core/pulls{/number}","milestones_url":"https://api.github.com/repos/mostjs/core/milestones{/number}","notifications_url":"https://api.github.com/repos/mostjs/core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mostjs/core/labels{/name}","releases_url":"https://api.github.com/repos/mostjs/core/releases{/id}","deployments_url":"https://api.github.com/repos/mostjs/core/deployments","created_at":"2016-12-23T14:27:44Z","updated_at":"2018-05-01T01:09:48Z","pushed_at":"2018-04-23T12:33:46Z","git_url":"git://github.com/mostjs/core.git","ssh_url":"git@github.com:mostjs/core.git","clone_url":"https://github.com/mostjs/core.git","svn_url":"https://github.com/mostjs/core","homepage":"http://mostcore.rtfd.io","size":1649,"stargazers_count":99,"watchers_count":99,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"archived":false,"open_issues_count":19,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":17,"open_issues":19,"watchers":99,"default_branch":"master"}},"base":{"label":"mostjs:master","ref":"master","sha":"3962cf735d7aaf66095f87cb11d55f1f359a56ec","user":{"login":"mostjs","id":15834413,"avatar_url":"https://avatars0.githubusercontent.com/u/15834413?v=4","gravatar_id":"","url":"https://api.github.com/users/mostjs","html_url":"https://github.com/mostjs","followers_url":"https://api.github.com/users/mostjs/followers","following_url":"https://api.github.com/users/mostjs/following{/other_user}","gists_url":"https://api.github.com/users/mostjs/gists{/gist_id}","starred_url":"https://api.github.com/users/mostjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mostjs/subscriptions","organizations_url":"https://api.github.com/users/mostjs/orgs","repos_url":"https://api.github.com/users/mostjs/repos","events_url":"https://api.github.com/users/mostjs/events{/privacy}","received_events_url":"https://api.github.com/users/mostjs/received_events","type":"Organization","site_admin":false},"repo":{"id":77230382,"name":"core","full_name":"mostjs/core","owner":{"login":"mostjs","id":15834413,"avatar_url":"https://avatars0.githubusercontent.com/u/15834413?v=4","gravatar_id":"","url":"https://api.github.com/users/mostjs","html_url":"https://github.com/mostjs","followers_url":"https://api.github.com/users/mostjs/followers","following_url":"https://api.github.com/users/mostjs/following{/other_user}","gists_url":"https://api.github.com/users/mostjs/gists{/gist_id}","starred_url":"https://api.github.com/users/mostjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mostjs/subscriptions","organizations_url":"https://api.github.com/users/mostjs/orgs","repos_url":"https://api.github.com/users/mostjs/repos","events_url":"https://api.github.com/users/mostjs/events{/privacy}","received_events_url":"https://api.github.com/users/mostjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mostjs/core","description":"Most.js core event stream","fork":false,"url":"https://api.github.com/repos/mostjs/core","forks_url":"https://api.github.com/repos/mostjs/core/forks","keys_url":"https://api.github.com/repos/mostjs/core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mostjs/core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mostjs/core/teams","hooks_url":"https://api.github.com/repos/mostjs/core/hooks","issue_events_url":"https://api.github.com/repos/mostjs/core/issues/events{/number}","events_url":"https://api.github.com/repos/mostjs/core/events","assignees_url":"https://api.github.com/repos/mostjs/core/assignees{/user}","branches_url":"https://api.github.com/repos/mostjs/core/branches{/branch}","tags_url":"https://api.github.com/repos/mostjs/core/tags","blobs_url":"https://api.github.com/repos/mostjs/core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mostjs/core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mostjs/core/git/refs{/sha}","trees_url":"https://api.github.com/repos/mostjs/core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mostjs/core/statuses/{sha}","languages_url":"https://api.github.com/repos/mostjs/core/languages","stargazers_url":"https://api.github.com/repos/mostjs/core/stargazers","contributors_url":"https://api.github.com/repos/mostjs/core/contributors","subscribers_url":"https://api.github.com/repos/mostjs/core/subscribers","subscription_url":"https://api.github.com/repos/mostjs/core/subscription","commits_url":"https://api.github.com/repos/mostjs/core/commits{/sha}","git_commits_url":"https://api.github.com/repos/mostjs/core/git/commits{/sha}","comments_url":"https://api.github.com/repos/mostjs/core/comments{/number}","issue_comment_url":"https://api.github.com/repos/mostjs/core/issues/comments{/number}","contents_url":"https://api.github.com/repos/mostjs/core/contents/{+path}","compare_url":"https://api.github.com/repos/mostjs/core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mostjs/core/merges","archive_url":"https://api.github.com/repos/mostjs/core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mostjs/core/downloads","issues_url":"https://api.github.com/repos/mostjs/core/issues{/number}","pulls_url":"https://api.github.com/repos/mostjs/core/pulls{/number}","milestones_url":"https://api.github.com/repos/mostjs/core/milestones{/number}","notifications_url":"https://api.github.com/repos/mostjs/core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mostjs/core/labels{/name}","releases_url":"https://api.github.com/repos/mostjs/core/releases{/id}","deployments_url":"https://api.github.com/repos/mostjs/core/deployments","created_at":"2016-12-23T14:27:44Z","updated_at":"2018-05-01T01:09:48Z","pushed_at":"2018-04-23T12:33:46Z","git_url":"git://github.com/mostjs/core.git","ssh_url":"git@github.com:mostjs/core.git","clone_url":"https://github.com/mostjs/core.git","svn_url":"https://github.com/mostjs/core","homepage":"http://mostcore.rtfd.io","size":1649,"stargazers_count":99,"watchers_count":99,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"archived":false,"open_issues_count":19,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":17,"open_issues":19,"watchers":99,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mostjs/core/pulls/235"},"html":{"href":"https://github.com/mostjs/core/pull/235"},"issue":{"href":"https://api.github.com/repos/mostjs/core/issues/235"},"comments":{"href":"https://api.github.com/repos/mostjs/core/issues/235/comments"},"review_comments":{"href":"https://api.github.com/repos/mostjs/core/pulls/235/comments"},"review_comment":{"href":"https://api.github.com/repos/mostjs/core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mostjs/core/pulls/235/commits"},"statuses":{"href":"https://api.github.com/repos/mostjs/core/statuses/1685078eb2c627bc31649a37ab93516170cf25ef"}},"author_association":"OWNER"}}
{"actor":{"display_login":"Frikki"}}