{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/jest/pulls/comments/140889615","pull_request_review_id":65026278,"id":140889615,"diff_hunk":"@@ -0,0 +1,95 @@\n+/**\n+ * Copyright (c) 2017-present, Facebook, Inc.\n+ * All rights reserved.\n+ *\n+ * This source code is licensed under the BSD-style license found in the\n+ * LICENSE file in the root directory of this source tree. An additional grant\n+ * of patent rights can be found in the PATENTS file in the same directory.\n+ */\n+\n+'use strict';\n+\n+import type {JestChildMessage} from './types';\n+\n+let file = null;\n+\n+/**\n+ * This file is a small bootstrapper for workers. It sets up the communication\n+ * between the worker and the parent process, interpreting parent messages and\n+ * sending results back.\n+ *\n+ * The file loaded will be lazily initialized the first time any of the workers\n+ * is called. This is done for optimal performance: if the farm is initialized,\n+ * but no call is made to it, child Node processes will be consuming the least\n+ * possible amount of memory.\n+ *\n+ * If an invalid message is detected, the child will exit (by throwing) with a\n+ * non-zero exit code.\n+ */\n+process.on('message', (request: JestChildMessage) => {\n+  switch (request.type) {\n+    case 'initialize':\n+      file = request.file;\n+      break;\n+\n+    case 'call':\n+      execMethod(request.method, request.args);\n+      break;\n+\n+    case 'end':\n+      process.exit(0);\n+      break;\n+\n+    default:\n+      throw new TypeError(\n+        'Unexpected request from parent process: ' + request.type,\n+      );\n+  }\n+});\n+\n+function reportSuccess(result: any) {\n+  if (!process || !process.send) {\n+    throw new Error('Child can only be used when forking a process');\n+  }\n+\n+  process.send({\n+    result,\n+    type: 'ok',\n+  });\n+}\n+\n+function reportError(error: Error) {\n+  if (!process || !process.send) {\n+    throw new Error('Child can only be used when forking a process');\n+  }\n+\n+  process.send({\n+    constructor: error.constructor.name,\n+    message: error.message,\n+    stack: error.stack,\n+    type: 'error',\n+  });\n+}\n+\n+function execMethod(method: string, args: $ReadOnlyArray<any>): void {\n+  // $FlowFixMe: This has to be a dynamic require.\n+  const main = require(file);\n+  let result;\n+\n+  try {\n+    if (method === '') {\n+      result = (main.__esModule ? main['default'] : main).apply(global, args);\n+    } else {\n+      result = main[method].apply(main, args);\n+    }\n+  } catch (err) {\n+    reportError(err);\n+    return;\n+  }\n+\n+  if (result && typeof result.then === 'function') {\n+    result.then(reportSuccess, reportError);\n+  } else {\n+    reportSuccess(result);","path":"packages/jest-parallel/src/child.js","position":93,"original_position":93,"commit_id":"1319e67c79537c9f421c77462564754d62501866","original_commit_id":"1319e67c79537c9f421c77462564754d62501866","user":{"login":"cpojer","id":13352,"avatar_url":"https://avatars0.githubusercontent.com/u/13352?v=4","gravatar_id":"","url":"https://api.github.com/users/cpojer","html_url":"https://github.com/cpojer","followers_url":"https://api.github.com/users/cpojer/followers","following_url":"https://api.github.com/users/cpojer/following{/other_user}","gists_url":"https://api.github.com/users/cpojer/gists{/gist_id}","starred_url":"https://api.github.com/users/cpojer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpojer/subscriptions","organizations_url":"https://api.github.com/users/cpojer/orgs","repos_url":"https://api.github.com/users/cpojer/repos","events_url":"https://api.github.com/users/cpojer/events{/privacy}","received_events_url":"https://api.github.com/users/cpojer/received_events","type":"User","site_admin":false},"body":"is there any possibility that `reportSuccess` could throw and we'd need to handle an error here?","created_at":"2017-09-25T20:32:38Z","updated_at":"2017-09-25T20:32:38Z","html_url":"https://github.com/facebook/jest/pull/4497#discussion_r140889615","pull_request_url":"https://api.github.com/repos/facebook/jest/pulls/4497","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/facebook/jest/pulls/comments/140889615"},"html":{"href":"https://github.com/facebook/jest/pull/4497#discussion_r140889615"},"pull_request":{"href":"https://api.github.com/repos/facebook/jest/pulls/4497"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/jest/pulls/4497","id":141492637,"html_url":"https://github.com/facebook/jest/pull/4497","diff_url":"https://github.com/facebook/jest/pull/4497.diff","patch_url":"https://github.com/facebook/jest/pull/4497.patch","issue_url":"https://api.github.com/repos/facebook/jest/issues/4497","number":4497,"state":"open","locked":false,"title":"Initial version of jest-parallel","user":{"login":"mjesun","id":829269,"avatar_url":"https://avatars3.githubusercontent.com/u/829269?v=4","gravatar_id":"","url":"https://api.github.com/users/mjesun","html_url":"https://github.com/mjesun","followers_url":"https://api.github.com/users/mjesun/followers","following_url":"https://api.github.com/users/mjesun/following{/other_user}","gists_url":"https://api.github.com/users/mjesun/gists{/gist_id}","starred_url":"https://api.github.com/users/mjesun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjesun/subscriptions","organizations_url":"https://api.github.com/users/mjesun/orgs","repos_url":"https://api.github.com/users/mjesun/repos","events_url":"https://api.github.com/users/mjesun/events{/privacy}","received_events_url":"https://api.github.com/users/mjesun/received_events","type":"User","site_admin":false},"body":"This PR introduces a new module, `jest-parallel`, intended to allow heavy task parallelization over multiple workers. \r\n\r\nThe module has a few advantages over the currently one used both in `jest` and `metro-bundler`:\r\n\r\n* 100% `flow`-ified.\r\n\r\n* 100% test coverage on it, all statements, methods and branches.\r\n\r\n* Slightly faster than the currenly used one.\r\n\r\n* Natively provides a `Promise` based interface, which allow us to avoid the extra wrapping layer in order to be used with `async`/`await.\r\n\r\n* It only has one single dependency (`merge-stream`), which we could also remove.\r\n\r\n* Lazily instantiated code in worker, meaning no code is loaded on child processes until the first call is done (lazy require). This allows to spawn a farm with minimal RAM consumption, and only load them when needed.\r\n\r\n* Sticky workers: tasks will be processed by the first available worker if no stickyness is needed, or by a particular one if the task is forced to do so. Specially useful for workers implementing caches.\r\n\r\n\r\n## Performance test\r\n\r\nIt can be run by doing `node --expose-gc test.js` under `__performance_tests__`. Note that the percentage improvement shown (~ 5%) applies to 10,000 calls, meaning the performance improvement per single call is negligible. The test implements a `Promise` wrapper over the current implementation, so we can equivalently test both implementations as we use them in real scenarios.\r\n\r\n```\r\n---------------------------------------------------------------------------\r\njest-parallel: { globalTime: 735, processingTime: 713 }\r\nworker-farm: { globalTime: 777, processingTime: 757 }\r\n---------------------------------------------------------------------------\r\njest-parallel: { globalTime: 753, processingTime: 734 }\r\nworker-farm: { globalTime: 854, processingTime: 838 }\r\n---------------------------------------------------------------------------\r\njest-parallel: { globalTime: 752, processingTime: 732 }\r\nworker-farm: { globalTime: 771, processingTime: 753 }\r\n---------------------------------------------------------------------------\r\njest-parallel: { globalTime: 733, processingTime: 709 }\r\nworker-farm: { globalTime: 815, processingTime: 798 }\r\n---------------------------------------------------------------------------\r\njest-parallel: { globalTime: 766, processingTime: 747 }\r\nworker-farm: { globalTime: 750, processingTime: 731 }\r\n---------------------------------------------------------------------------\r\njest-parallel: { globalTime: 740, processingTime: 721 }\r\nworker-farm: { globalTime: 782, processingTime: 764 }\r\n---------------------------------------------------------------------------\r\njest-parallel: { globalTime: 733, processingTime: 708 }\r\nworker-farm: { globalTime: 766, processingTime: 753 }\r\n---------------------------------------------------------------------------\r\njest-parallel: { globalTime: 752, processingTime: 731 }\r\nworker-farm: { globalTime: 770, processingTime: 751 }\r\n---------------------------------------------------------------------------\r\njest-parallel: { globalTime: 743, processingTime: 721 }\r\nworker-farm: { globalTime: 790, processingTime: 772 }\r\n---------------------------------------------------------------------------\r\njest-parallel: { globalTime: 745, processingTime: 726 }\r\nworker-farm: { globalTime: 769, processingTime: 752 }\r\n---------------------------------------------------------------------------\r\ntotal worker-farm: { wFGT: 7844, wFPT: 7669 }\r\ntotal jest-parallel: { jPGT: 7452, jPPT: 7242 }\r\n---------------------------------------------------------------------------\r\n% improvement over 10000 calls (global time): 4.997450280469148\r\n% improvement over 10000 calls (processing time): 5.567870648063633\r\n```\r\n\r\n\r\n## Coverage\r\n\r\n![Coverage](https://user-images.githubusercontent.com/829269/30757044-c75a0be0-9fff-11e7-9361-d963f4177751.png)","created_at":"2017-09-17T16:26:27Z","updated_at":"2017-09-25T20:32:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"894badf95ae5e683e5d06c16da2d923fcd0dc90b","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/facebook/jest/pulls/4497/commits","review_comments_url":"https://api.github.com/repos/facebook/jest/pulls/4497/comments","review_comment_url":"https://api.github.com/repos/facebook/jest/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/jest/issues/4497/comments","statuses_url":"https://api.github.com/repos/facebook/jest/statuses/1319e67c79537c9f421c77462564754d62501866","head":{"label":"mjesun:jest-parallel","ref":"jest-parallel","sha":"1319e67c79537c9f421c77462564754d62501866","user":{"login":"mjesun","id":829269,"avatar_url":"https://avatars3.githubusercontent.com/u/829269?v=4","gravatar_id":"","url":"https://api.github.com/users/mjesun","html_url":"https://github.com/mjesun","followers_url":"https://api.github.com/users/mjesun/followers","following_url":"https://api.github.com/users/mjesun/following{/other_user}","gists_url":"https://api.github.com/users/mjesun/gists{/gist_id}","starred_url":"https://api.github.com/users/mjesun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjesun/subscriptions","organizations_url":"https://api.github.com/users/mjesun/orgs","repos_url":"https://api.github.com/users/mjesun/repos","events_url":"https://api.github.com/users/mjesun/events{/privacy}","received_events_url":"https://api.github.com/users/mjesun/received_events","type":"User","site_admin":false},"repo":{"id":94242212,"name":"jest","full_name":"mjesun/jest","owner":{"login":"mjesun","id":829269,"avatar_url":"https://avatars3.githubusercontent.com/u/829269?v=4","gravatar_id":"","url":"https://api.github.com/users/mjesun","html_url":"https://github.com/mjesun","followers_url":"https://api.github.com/users/mjesun/followers","following_url":"https://api.github.com/users/mjesun/following{/other_user}","gists_url":"https://api.github.com/users/mjesun/gists{/gist_id}","starred_url":"https://api.github.com/users/mjesun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjesun/subscriptions","organizations_url":"https://api.github.com/users/mjesun/orgs","repos_url":"https://api.github.com/users/mjesun/repos","events_url":"https://api.github.com/users/mjesun/events{/privacy}","received_events_url":"https://api.github.com/users/mjesun/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mjesun/jest","description":"🃏 Delightful JavaScript Testing.","fork":true,"url":"https://api.github.com/repos/mjesun/jest","forks_url":"https://api.github.com/repos/mjesun/jest/forks","keys_url":"https://api.github.com/repos/mjesun/jest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mjesun/jest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mjesun/jest/teams","hooks_url":"https://api.github.com/repos/mjesun/jest/hooks","issue_events_url":"https://api.github.com/repos/mjesun/jest/issues/events{/number}","events_url":"https://api.github.com/repos/mjesun/jest/events","assignees_url":"https://api.github.com/repos/mjesun/jest/assignees{/user}","branches_url":"https://api.github.com/repos/mjesun/jest/branches{/branch}","tags_url":"https://api.github.com/repos/mjesun/jest/tags","blobs_url":"https://api.github.com/repos/mjesun/jest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mjesun/jest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mjesun/jest/git/refs{/sha}","trees_url":"https://api.github.com/repos/mjesun/jest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mjesun/jest/statuses/{sha}","languages_url":"https://api.github.com/repos/mjesun/jest/languages","stargazers_url":"https://api.github.com/repos/mjesun/jest/stargazers","contributors_url":"https://api.github.com/repos/mjesun/jest/contributors","subscribers_url":"https://api.github.com/repos/mjesun/jest/subscribers","subscription_url":"https://api.github.com/repos/mjesun/jest/subscription","commits_url":"https://api.github.com/repos/mjesun/jest/commits{/sha}","git_commits_url":"https://api.github.com/repos/mjesun/jest/git/commits{/sha}","comments_url":"https://api.github.com/repos/mjesun/jest/comments{/number}","issue_comment_url":"https://api.github.com/repos/mjesun/jest/issues/comments{/number}","contents_url":"https://api.github.com/repos/mjesun/jest/contents/{+path}","compare_url":"https://api.github.com/repos/mjesun/jest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mjesun/jest/merges","archive_url":"https://api.github.com/repos/mjesun/jest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mjesun/jest/downloads","issues_url":"https://api.github.com/repos/mjesun/jest/issues{/number}","pulls_url":"https://api.github.com/repos/mjesun/jest/pulls{/number}","milestones_url":"https://api.github.com/repos/mjesun/jest/milestones{/number}","notifications_url":"https://api.github.com/repos/mjesun/jest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mjesun/jest/labels{/name}","releases_url":"https://api.github.com/repos/mjesun/jest/releases{/id}","deployments_url":"https://api.github.com/repos/mjesun/jest/deployments","created_at":"2017-06-13T18:00:17Z","updated_at":"2017-06-13T18:00:22Z","pushed_at":"2017-09-22T17:35:17Z","git_url":"git://github.com/mjesun/jest.git","ssh_url":"git@github.com:mjesun/jest.git","clone_url":"https://github.com/mjesun/jest.git","svn_url":"https://github.com/mjesun/jest","homepage":"http://facebook.github.io/jest/","size":19489,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"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":"facebook:master","ref":"master","sha":"f92c3be685c529e7885e546e2b90bf0f8374e171","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars3.githubusercontent.com/u/69631?v=4","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":15062869,"name":"jest","full_name":"facebook/jest","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars3.githubusercontent.com/u/69631?v=4","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/jest","description":"🃏 Delightful JavaScript Testing.","fork":false,"url":"https://api.github.com/repos/facebook/jest","forks_url":"https://api.github.com/repos/facebook/jest/forks","keys_url":"https://api.github.com/repos/facebook/jest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/jest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/jest/teams","hooks_url":"https://api.github.com/repos/facebook/jest/hooks","issue_events_url":"https://api.github.com/repos/facebook/jest/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/jest/events","assignees_url":"https://api.github.com/repos/facebook/jest/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/jest/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/jest/tags","blobs_url":"https://api.github.com/repos/facebook/jest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/jest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/jest/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/jest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/jest/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/jest/languages","stargazers_url":"https://api.github.com/repos/facebook/jest/stargazers","contributors_url":"https://api.github.com/repos/facebook/jest/contributors","subscribers_url":"https://api.github.com/repos/facebook/jest/subscribers","subscription_url":"https://api.github.com/repos/facebook/jest/subscription","commits_url":"https://api.github.com/repos/facebook/jest/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/jest/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/jest/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/jest/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/jest/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/jest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/jest/merges","archive_url":"https://api.github.com/repos/facebook/jest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/jest/downloads","issues_url":"https://api.github.com/repos/facebook/jest/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/jest/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/jest/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/jest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/jest/labels{/name}","releases_url":"https://api.github.com/repos/facebook/jest/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/jest/deployments","created_at":"2013-12-10T00:18:04Z","updated_at":"2017-09-25T18:52:15Z","pushed_at":"2017-09-25T19:58:06Z","git_url":"git://github.com/facebook/jest.git","ssh_url":"git@github.com:facebook/jest.git","clone_url":"https://github.com/facebook/jest.git","svn_url":"https://github.com/facebook/jest","homepage":"http://facebook.github.io/jest/","size":21851,"stargazers_count":12265,"watchers_count":12265,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1569,"mirror_url":null,"open_issues_count":202,"forks":1569,"open_issues":202,"watchers":12265,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/jest/pulls/4497"},"html":{"href":"https://github.com/facebook/jest/pull/4497"},"issue":{"href":"https://api.github.com/repos/facebook/jest/issues/4497"},"comments":{"href":"https://api.github.com/repos/facebook/jest/issues/4497/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/jest/pulls/4497/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/jest/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/jest/pulls/4497/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/jest/statuses/1319e67c79537c9f421c77462564754d62501866"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"cpojer"}}