{"action":"created","comment":{"url":"https://api.github.com/repos/xitu/gold-miner/pulls/comments/105527073","pull_request_review_id":26416264,"id":105527073,"diff_hunk":"@@ -129,40 +180,56 @@ functionarraySum(arr) {\n ```\n \n The `+=` step in the loop may seem simple. It may seem like you can compute this in one step, but because of dynamic typing, it takes more steps than you would expect.\n+执行循环中的 `+=` 一步似乎很简单。看起来你可以一步就得到计算结果，但由于 JavaScript 的动态类型，处理它所需要的步骤比你想象的多。\n \n Let’s assume that `arr` is an array of 100 integers. Once the code warms up, the baseline compiler will create a stub for each operation in the function. So there will be a stub for `sum += arr[i]`, which will handle the `+=` operation as integer addition.\n+假定 `arr` 是一个存放 100 个整数的数组。在代码执行几次后，基线编译器将为函数中的每个操作创建一个存根。`sum += arr[i]` 将会有一个把 `+=` 依据整数加法处理的存根。\n \n However,`sum` and `arr[i]` aren’t guaranteed to be integers. Because types are dynamic in JavaScript, there’s a chance that in a later iteration of the loop, `arr[i]` will be a string. Integer addition and string concatenation are two very different operations, so they would compile to very different machine code.\n+然而我们并不能保证 `sum` 和 `arr[i]` 一定是整数。因为在 JavaScript 中数据类型是动态的，有可能在下一次循环中的 `arr[i]` 是一个字符串。整数加法和字符串拼接是两个完全不同的操作，因此也会编译成非常不同的机器码。\n \n The way the JIT handles this is by compiling multiple baseline stubs. If a piece of code is monomorphic (that is, always called with the same types) it will get one stub. If it is polymorphic (called with different types from one pass through the code to another), then it will get a stub for each combination of types that has come through that operation.\n+JIT 处理这种情况的方法是编译多个基线存根。一段代码如果是单态的（即总被同一种类型调用），将得到一个存根。如果是多态的（即被不同类型调用），那么它将得到分别对应各类型组合操作的存根。\n \n This means that the JIT has to ask a lot of questions before it chooses a stub.\n+这意味着 JIT 在确定存根前要问许多问题。\n \n-![Decision tree showing 4 type checks](https://2r4s9p1yi1fa2jd7j43zph8r-wpengine.netdna-ssl.com/files/2017/02/02-08-decision_tree01-500x257.png) \n+![Decision tree showing 4 type checks](https://2r4s9p1yi1fa2jd7j43zph8r-wpengine.netdna-ssl.com/files/2017/02/02-08-decision_tree01-500x257.png)\n \n Because each line of code has its own set of stubs in the baseline compiler, the JIT needs to keep checking the types each time the line of code is executed. So for each iteration through the loop, it will have to ask the same questions.\n+在基线编译器中，由于每一行代码都有各自对应的存根，每次代码运行时，JIT 要不断检查该行代码的操作类型。因此在每次循环时，JIT 都要询问相同的问题。\n \n ![Code looping with JIT asking what types are being used in each loop](https://2r4s9p1yi1fa2jd7j43zph8r-wpengine.netdna-ssl.com/files/2017/02/02-09-jit_loop02-500x323.png)\n \n The code would execute a lot faster if the JIT didn’t need to repeat those checks. And that’s one of the things the optimizing compiler does.\n+如果 JIT 不需要重复这些检查，代码运行速度会加快很多。这就是优化编译器的工作之一了。\n \n In the optimizing compiler, the whole function is compiled together. The type checks are moved so that they happen before the loop.\n+在优化编译器中，整个函数会被一起编译。The type checks are moved 所以类型检查可以在循环开始前完成。\n \n ![Code looping with questions being asked ahead of time](https://2r4s9p1yi1fa2jd7j43zph8r-wpengine.netdna-ssl.com/files/2017/02/02-10-jit_loop02-500x318.png)\n \n Some JITs optimize this even further. For example, in Firefox there’s a special classification for arrays that only contain integers. If `arr` is one of these arrays, then the JIT doesn’t need to check if `arr[i]` is an integer. This means that the JIT can do all of the type checks before it enters the loop.\n+一些 JIT 编译器做了进一步优化。例如，在 Firefox 中为仅包含整数的数组设立了一个特殊分类。如果 `arr` 是在这个分类下的数组，JIT 就不需要检查 `arr[i]` 是否是整数了。这意味着 JIT 可以在进入循环前完成所有类型检查。\n \n ## Conclusion ##\n+## 总结 ##\n \n That is the JIT in a nutshell. It makes JavaScript run faster by monitoring the code as it’s running it and sending hot code paths to be optimized. This has resulted in many-fold performance improvements for most JavaScript applications.\n+简而言之，这就是 JIT。它通过监控代码运行确定高频代码，并进行优化，加快了 JavaScript 的运行速度。","path":"TODO/a-crash-course-in-just-in-time-jit-compilers.md","position":222,"original_position":222,"commit_id":"bf36b6a4b3025bae2def6106d8203351685979bd","original_commit_id":"bf36b6a4b3025bae2def6106d8203351685979bd","user":{"login":"Tina92","id":17871352,"avatar_url":"https://avatars2.githubusercontent.com/u/17871352?v=3","gravatar_id":"","url":"https://api.github.com/users/Tina92","html_url":"https://github.com/Tina92","followers_url":"https://api.github.com/users/Tina92/followers","following_url":"https://api.github.com/users/Tina92/following{/other_user}","gists_url":"https://api.github.com/users/Tina92/gists{/gist_id}","starred_url":"https://api.github.com/users/Tina92/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tina92/subscriptions","organizations_url":"https://api.github.com/users/Tina92/orgs","repos_url":"https://api.github.com/users/Tina92/repos","events_url":"https://api.github.com/users/Tina92/events{/privacy}","received_events_url":"https://api.github.com/users/Tina92/received_events","type":"User","site_admin":false},"body":"第二句没有翻译","created_at":"2017-03-11T06:14:03Z","updated_at":"2017-03-11T06:16:34Z","html_url":"https://github.com/xitu/gold-miner/pull/1348#discussion_r105527073","pull_request_url":"https://api.github.com/repos/xitu/gold-miner/pulls/1348","_links":{"self":{"href":"https://api.github.com/repos/xitu/gold-miner/pulls/comments/105527073"},"html":{"href":"https://github.com/xitu/gold-miner/pull/1348#discussion_r105527073"},"pull_request":{"href":"https://api.github.com/repos/xitu/gold-miner/pulls/1348"}}},"pull_request":{"url":"https://api.github.com/repos/xitu/gold-miner/pulls/1348","id":109745767,"html_url":"https://github.com/xitu/gold-miner/pull/1348","diff_url":"https://github.com/xitu/gold-miner/pull/1348.diff","patch_url":"https://github.com/xitu/gold-miner/pull/1348.patch","issue_url":"https://api.github.com/repos/xitu/gold-miner/issues/1348","number":1348,"state":"open","locked":false,"title":"JIT 编译器快速入门 [ part 2 ]","user":{"login":"zhouzihanntu","id":14007659,"avatar_url":"https://avatars3.githubusercontent.com/u/14007659?v=3","gravatar_id":"","url":"https://api.github.com/users/zhouzihanntu","html_url":"https://github.com/zhouzihanntu","followers_url":"https://api.github.com/users/zhouzihanntu/followers","following_url":"https://api.github.com/users/zhouzihanntu/following{/other_user}","gists_url":"https://api.github.com/users/zhouzihanntu/gists{/gist_id}","starred_url":"https://api.github.com/users/zhouzihanntu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhouzihanntu/subscriptions","organizations_url":"https://api.github.com/users/zhouzihanntu/orgs","repos_url":"https://api.github.com/users/zhouzihanntu/repos","events_url":"https://api.github.com/users/zhouzihanntu/events{/privacy}","received_events_url":"https://api.github.com/users/zhouzihanntu/received_events","type":"User","site_admin":false},"body":"初稿～ 辛苦校对的同志了","created_at":"2017-03-08T17:37:09Z","updated_at":"2017-03-11T06:16:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aa38744fb25c3664f62508cfe88b4baf3db83ec3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/xitu/gold-miner/pulls/1348/commits","review_comments_url":"https://api.github.com/repos/xitu/gold-miner/pulls/1348/comments","review_comment_url":"https://api.github.com/repos/xitu/gold-miner/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xitu/gold-miner/issues/1348/comments","statuses_url":"https://api.github.com/repos/xitu/gold-miner/statuses/bf36b6a4b3025bae2def6106d8203351685979bd","head":{"label":"zhouzihanntu:master","ref":"master","sha":"bf36b6a4b3025bae2def6106d8203351685979bd","user":{"login":"zhouzihanntu","id":14007659,"avatar_url":"https://avatars3.githubusercontent.com/u/14007659?v=3","gravatar_id":"","url":"https://api.github.com/users/zhouzihanntu","html_url":"https://github.com/zhouzihanntu","followers_url":"https://api.github.com/users/zhouzihanntu/followers","following_url":"https://api.github.com/users/zhouzihanntu/following{/other_user}","gists_url":"https://api.github.com/users/zhouzihanntu/gists{/gist_id}","starred_url":"https://api.github.com/users/zhouzihanntu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhouzihanntu/subscriptions","organizations_url":"https://api.github.com/users/zhouzihanntu/orgs","repos_url":"https://api.github.com/users/zhouzihanntu/repos","events_url":"https://api.github.com/users/zhouzihanntu/events{/privacy}","received_events_url":"https://api.github.com/users/zhouzihanntu/received_events","type":"User","site_admin":false},"repo":{"id":76437196,"name":"gold-miner","full_name":"zhouzihanntu/gold-miner","owner":{"login":"zhouzihanntu","id":14007659,"avatar_url":"https://avatars3.githubusercontent.com/u/14007659?v=3","gravatar_id":"","url":"https://api.github.com/users/zhouzihanntu","html_url":"https://github.com/zhouzihanntu","followers_url":"https://api.github.com/users/zhouzihanntu/followers","following_url":"https://api.github.com/users/zhouzihanntu/following{/other_user}","gists_url":"https://api.github.com/users/zhouzihanntu/gists{/gist_id}","starred_url":"https://api.github.com/users/zhouzihanntu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhouzihanntu/subscriptions","organizations_url":"https://api.github.com/users/zhouzihanntu/orgs","repos_url":"https://api.github.com/users/zhouzihanntu/repos","events_url":"https://api.github.com/users/zhouzihanntu/events{/privacy}","received_events_url":"https://api.github.com/users/zhouzihanntu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zhouzihanntu/gold-miner","description":"掘金翻译计划，翻译掘金上优质的英文文章","fork":true,"url":"https://api.github.com/repos/zhouzihanntu/gold-miner","forks_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/forks","keys_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/teams","hooks_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/hooks","issue_events_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/issues/events{/number}","events_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/events","assignees_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/assignees{/user}","branches_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/branches{/branch}","tags_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/tags","blobs_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/git/refs{/sha}","trees_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/statuses/{sha}","languages_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/languages","stargazers_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/stargazers","contributors_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/contributors","subscribers_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/subscribers","subscription_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/subscription","commits_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/commits{/sha}","git_commits_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/git/commits{/sha}","comments_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/comments{/number}","issue_comment_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/issues/comments{/number}","contents_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/contents/{+path}","compare_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/merges","archive_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/downloads","issues_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/issues{/number}","pulls_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/pulls{/number}","milestones_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/milestones{/number}","notifications_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/labels{/name}","releases_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/releases{/id}","deployments_url":"https://api.github.com/repos/zhouzihanntu/gold-miner/deployments","created_at":"2016-12-14T07:52:34Z","updated_at":"2016-12-14T07:26:08Z","pushed_at":"2017-03-09T09:02:16Z","git_url":"git://github.com/zhouzihanntu/gold-miner.git","ssh_url":"git@github.com:zhouzihanntu/gold-miner.git","clone_url":"https://github.com/zhouzihanntu/gold-miner.git","svn_url":"https://github.com/zhouzihanntu/gold-miner","homepage":"http://juejin.im","size":19830,"stargazers_count":0,"watchers_count":0,"language":null,"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":"xitu:master","ref":"master","sha":"f1c83e825d67039212c34dbcdb28cb64064ea6e4","user":{"login":"xitu","id":10482599,"avatar_url":"https://avatars1.githubusercontent.com/u/10482599?v=3","gravatar_id":"","url":"https://api.github.com/users/xitu","html_url":"https://github.com/xitu","followers_url":"https://api.github.com/users/xitu/followers","following_url":"https://api.github.com/users/xitu/following{/other_user}","gists_url":"https://api.github.com/users/xitu/gists{/gist_id}","starred_url":"https://api.github.com/users/xitu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xitu/subscriptions","organizations_url":"https://api.github.com/users/xitu/orgs","repos_url":"https://api.github.com/users/xitu/repos","events_url":"https://api.github.com/users/xitu/events{/privacy}","received_events_url":"https://api.github.com/users/xitu/received_events","type":"Organization","site_admin":false},"repo":{"id":45512989,"name":"gold-miner","full_name":"xitu/gold-miner","owner":{"login":"xitu","id":10482599,"avatar_url":"https://avatars1.githubusercontent.com/u/10482599?v=3","gravatar_id":"","url":"https://api.github.com/users/xitu","html_url":"https://github.com/xitu","followers_url":"https://api.github.com/users/xitu/followers","following_url":"https://api.github.com/users/xitu/following{/other_user}","gists_url":"https://api.github.com/users/xitu/gists{/gist_id}","starred_url":"https://api.github.com/users/xitu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xitu/subscriptions","organizations_url":"https://api.github.com/users/xitu/orgs","repos_url":"https://api.github.com/users/xitu/repos","events_url":"https://api.github.com/users/xitu/events{/privacy}","received_events_url":"https://api.github.com/users/xitu/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xitu/gold-miner","description":"掘金翻译计划，翻译掘金上优质的英文文章","fork":false,"url":"https://api.github.com/repos/xitu/gold-miner","forks_url":"https://api.github.com/repos/xitu/gold-miner/forks","keys_url":"https://api.github.com/repos/xitu/gold-miner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xitu/gold-miner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xitu/gold-miner/teams","hooks_url":"https://api.github.com/repos/xitu/gold-miner/hooks","issue_events_url":"https://api.github.com/repos/xitu/gold-miner/issues/events{/number}","events_url":"https://api.github.com/repos/xitu/gold-miner/events","assignees_url":"https://api.github.com/repos/xitu/gold-miner/assignees{/user}","branches_url":"https://api.github.com/repos/xitu/gold-miner/branches{/branch}","tags_url":"https://api.github.com/repos/xitu/gold-miner/tags","blobs_url":"https://api.github.com/repos/xitu/gold-miner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xitu/gold-miner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xitu/gold-miner/git/refs{/sha}","trees_url":"https://api.github.com/repos/xitu/gold-miner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xitu/gold-miner/statuses/{sha}","languages_url":"https://api.github.com/repos/xitu/gold-miner/languages","stargazers_url":"https://api.github.com/repos/xitu/gold-miner/stargazers","contributors_url":"https://api.github.com/repos/xitu/gold-miner/contributors","subscribers_url":"https://api.github.com/repos/xitu/gold-miner/subscribers","subscription_url":"https://api.github.com/repos/xitu/gold-miner/subscription","commits_url":"https://api.github.com/repos/xitu/gold-miner/commits{/sha}","git_commits_url":"https://api.github.com/repos/xitu/gold-miner/git/commits{/sha}","comments_url":"https://api.github.com/repos/xitu/gold-miner/comments{/number}","issue_comment_url":"https://api.github.com/repos/xitu/gold-miner/issues/comments{/number}","contents_url":"https://api.github.com/repos/xitu/gold-miner/contents/{+path}","compare_url":"https://api.github.com/repos/xitu/gold-miner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xitu/gold-miner/merges","archive_url":"https://api.github.com/repos/xitu/gold-miner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xitu/gold-miner/downloads","issues_url":"https://api.github.com/repos/xitu/gold-miner/issues{/number}","pulls_url":"https://api.github.com/repos/xitu/gold-miner/pulls{/number}","milestones_url":"https://api.github.com/repos/xitu/gold-miner/milestones{/number}","notifications_url":"https://api.github.com/repos/xitu/gold-miner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xitu/gold-miner/labels{/name}","releases_url":"https://api.github.com/repos/xitu/gold-miner/releases{/id}","deployments_url":"https://api.github.com/repos/xitu/gold-miner/deployments","created_at":"2015-11-04T03:29:13Z","updated_at":"2017-03-11T06:03:52Z","pushed_at":"2017-03-11T04:21:04Z","git_url":"git://github.com/xitu/gold-miner.git","ssh_url":"git@github.com:xitu/gold-miner.git","clone_url":"https://github.com/xitu/gold-miner.git","svn_url":"https://github.com/xitu/gold-miner","homepage":"http://juejin.im/tag/掘金翻译计划","size":19968,"stargazers_count":6631,"watchers_count":6631,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1273,"mirror_url":null,"open_issues_count":38,"forks":1273,"open_issues":38,"watchers":6631,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xitu/gold-miner/pulls/1348"},"html":{"href":"https://github.com/xitu/gold-miner/pull/1348"},"issue":{"href":"https://api.github.com/repos/xitu/gold-miner/issues/1348"},"comments":{"href":"https://api.github.com/repos/xitu/gold-miner/issues/1348/comments"},"review_comments":{"href":"https://api.github.com/repos/xitu/gold-miner/pulls/1348/comments"},"review_comment":{"href":"https://api.github.com/repos/xitu/gold-miner/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xitu/gold-miner/pulls/1348/commits"},"statuses":{"href":"https://api.github.com/repos/xitu/gold-miner/statuses/bf36b6a4b3025bae2def6106d8203351685979bd"}}}}
{"actor":{"display_login":"Tina92"}}