Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3641951

Browse files
committed
add eventloop TODO
1 parent 4c23c2a commit 3641951

File tree

12 files changed

+109
-17
lines changed

12 files changed

+109
-17
lines changed

‎201709/runtime.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#### JavaScript 是如何执行的
44

5-
对于常见编译型语言(例如:Java)来说,编译步骤分为:词法分析->语法分析->语义检查->代码优化和字节生成
5+
对于常见编译型语言(例如:Java)来说,编译步骤分为:词法分析->语法分析->语义检查->代码优化和字节码生成
66

77
对于解释型语言(例如 JavaScript)来说,通过词法分析 -> 语法分析 -> 语法树,就可以开始解释执行了。
88

@@ -50,7 +50,7 @@ function scopeTest(){
5050

5151
我们常说的 V8 是 Google 发布的开源 JavaScript 引擎,采用 C++ 编写。SpiderMonkey(Mozilla,基于 C)、Rhino(Mozilla,基于 Java),而 Nodejs 依赖于 V8 引擎开发,接下来的内容是 JavaScript 在 V8 引擎中的运行状态,而类似的 JavaScript 现代引擎对于这些实现大同小异。
5252

53-
在本文的开头提到了编译型语言,解释型语言。JavaScript 是解释型语言,在生成 AST 之后,就开始一边解释,一边执行,但是有个弊端,当某段代码被多次执行时,它就有了可优化的空间(后面提到),而不用一次次的去重复之前的解释执行。
53+
在本文的开头提到了编译型语言,解释型语言。JavaScript 是解释型语言且`无类型`,在生成 AST 之后,就开始一边解释,一边执行,但是有个弊端,当某段代码被多次执行时,它就有了可优化的空间(比如类型判断优化),而不用一次次的去重复之前的解释执行。
5454
编译型语言如 JAVA,可以在执行前就进行优化编译,但是这会耗费大量的时间,显然不适用于 Web 交互。
5555

5656
于是就有了,JIT(Just-in-time),JIT 是两种模式的混合。
@@ -61,15 +61,15 @@ function scopeTest(){
6161

6262
1.在 JavaScript 引擎中增加一个监视器(也叫分析器)。监视器监控着代码的运行情况,记录代码一共运行了多少次、如何运行的等信息,如果同一行代码运行了几次,这个代码段就被标记成了 "warm",如果运行了很多次,则被标记成 "hot"。
6363

64-
2.(基线编译器)如果一段代码变成了 "warm",那么 JIT 就把它送到编译器去编译,并且把编译结果存储起来。比如,监视器监视到了,某行、某个变量执行同样的代码、使用了同样的变量类型,那么就会把编译后的版本,替换这一行代码的执行,并且存储。
64+
2.(基线编译器)如果一段代码变成了 "warm",那么 JIT 就把它送到基线编译器去编译,并且把编译结果存储起来。比如,监视器监视到了,某行、某个变量执行同样的代码、使用了同样的变量类型,那么就会把编译后的版本,替换这一行代码的执行,并且存储。
6565

6666
3.(优化编译器)如果一个代码段变得 "hot",监视器会把它发送到优化编译器中。生成一个更快速和高效的代码版本出来,并且存储。例如:循环加一个对象属性时,假设它是 INT 类型,优先做 INT 类型的判断
6767

6868
4.(去优化)可是对于 JavaScript 从来就没有确定这么一说,前 99 个对象属性保持着 INT 类型,可能第 100 个就没有这个属性了,那么这时候 JIT 会认为做了一个错误的假设,并且把优化代码丢掉,执行过程将会回到解释器或者基线编译器,这一过程叫做去优化。
6969

7070
###### 优化代码图例:
7171

72-
hot 代码
72+
"hot" 代码
7373

7474
![](../assets/2017_09_03.jpg)
7575

‎201710/eventloop.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Event Loop
2+
3+
// TODO
4+
5+
------
6+
7+
作者:肖沐宸,[github](https://github.com/cheogo)

‎GLOSSARY.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ Definition for this term
1414
- [JavaScript 有哪些引擎](http://www.cnblogs.com/gdutbean/archive/2012/02/21/2362003.html)
1515
- [V8 Design Elements](https://my.oschina.net/sub/blog/152628)
1616
- [JavaScript Just-in-time (JIT) 工作原理](http://huziketang.com/blog/posts/detail?postId=58c12f36a6d8a07e449fdd22)
17-
- [JS特性性能缺陷及JIT的解决方案](http://www.cnblogs.com/hyddd/archive/2013/02/06/2908110.html)
17+
- [JS特性性能缺陷及JIT的解决方案](http://www.cnblogs.com/hyddd/archive/2013/02/06/2908110.html)
18+
19+
## 参考文章-201710-eventloop
20+

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66

77
- [序章](https://cheogo.github.io/learn-javascript/201709/preface.html)
88
- [JavaScript 起源](https://cheogo.github.io/learn-javascript/201709/origin.html)
9-
- [JavaScript 语法解析、AST、V8、JIT](https://cheogo.github.io/learn-javascript/201709/runtime.html)
9+
- [JavaScript 语法解析、AST、V8、JIT](https://cheogo.github.io/learn-javascript/201709/runtime.html)
10+
- [Event loop](https://cheogo.github.io/learn-javascript/201709/eventloop.html)

‎SUMMARY.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
* [序章](201709/preface.md)
55
* [JavaScript 起源](201709/origin.md)
66
* [JavaScript 语法解析、AST、V8、JIT](201709/runtime.md)
7+
* [Event Loop](201709/eventloop.md)

‎docs/201709/origin.html‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@
145145

146146
</li>
147147

148+
<li class="chapter " data-level="1.5" data-path="eventloop.md">
149+
150+
<span>
151+
152+
153+
Event Loop
154+
155+
</a>
156+
157+
158+
159+
</li>
160+
148161

149162

150163

@@ -237,7 +250,7 @@ <h1 class="search-results-title">No results matching "<span class='search-query'
237250
<script>
238251
var gitbook = gitbook || [];
239252
gitbook.push(function() {
240-
gitbook.page.hasChanged({"page":{"title":"JavaScript 起源","level":"1.3","depth":1,"next":{"title":"JavaScript 语法解析、AST、V8、JIT","level":"1.4","depth":1,"path":"201709/runtime.md","ref":"201709/runtime.md","articles":[]},"previous":{"title":"序章","level":"1.2","depth":1,"path":"201709/preface.md","ref":"201709/preface.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["katex"],"pluginsConfig":{"katex":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"201709/origin.md","mtime":"2017年10月02日T07:25:22.000Z","type":"markdown"},"gitbook":{"version":"3.2.0","time":"2017年10月02日T07:25:36.000Z"},"basePath":"..","book":{"language":""}});
253+
gitbook.page.hasChanged({"page":{"title":"JavaScript 起源","level":"1.3","depth":1,"next":{"title":"JavaScript 语法解析、AST、V8、JIT","level":"1.4","depth":1,"path":"201709/runtime.md","ref":"201709/runtime.md","articles":[]},"previous":{"title":"序章","level":"1.2","depth":1,"path":"201709/preface.md","ref":"201709/preface.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["katex"],"pluginsConfig":{"katex":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"201709/origin.md","mtime":"2017年10月02日T07:25:22.000Z","type":"markdown"},"gitbook":{"version":"3.2.0","time":"2017年10月02日T07:44:49.950Z"},"basePath":"..","book":{"language":""}});
241254
});
242255
</script>
243256
</div>

‎docs/201709/preface.html‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@
145145

146146
</li>
147147

148+
<li class="chapter " data-level="1.5" data-path="eventloop.md">
149+
150+
<span>
151+
152+
153+
Event Loop
154+
155+
</a>
156+
157+
158+
159+
</li>
160+
148161

149162

150163

@@ -233,7 +246,7 @@ <h1 class="search-results-title">No results matching "<span class='search-query'
233246
<script>
234247
var gitbook = gitbook || [];
235248
gitbook.push(function() {
236-
gitbook.page.hasChanged({"page":{"title":"序章","level":"1.2","depth":1,"next":{"title":"JavaScript 起源","level":"1.3","depth":1,"path":"201709/origin.md","ref":"201709/origin.md","articles":[]},"previous":{"title":"目录","level":"1.1","depth":1,"path":"README.md","ref":"./README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["katex"],"pluginsConfig":{"katex":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"201709/preface.md","mtime":"2017年09月25日T10:56:50.000Z","type":"markdown"},"gitbook":{"version":"3.2.0","time":"2017年10月02日T07:25:36.000Z"},"basePath":"..","book":{"language":""}});
249+
gitbook.page.hasChanged({"page":{"title":"序章","level":"1.2","depth":1,"next":{"title":"JavaScript 起源","level":"1.3","depth":1,"path":"201709/origin.md","ref":"201709/origin.md","articles":[]},"previous":{"title":"目录","level":"1.1","depth":1,"path":"README.md","ref":"./README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["katex"],"pluginsConfig":{"katex":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"201709/preface.md","mtime":"2017年09月25日T10:56:50.000Z","type":"markdown"},"gitbook":{"version":"3.2.0","time":"2017年10月02日T07:44:49.950Z"},"basePath":"..","book":{"language":""}});
237250
});
238251
</script>
239252
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /