-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V8 性能优化杀手 #1828
V8 性能优化杀手 #1828
Conversation
TODO/Optimization-killers.md
Outdated
- `arguments[i]` **`i` 需要始终未 arguments 的合法整型索引,且不允许越界** | ||
- 除了 `.length` 和 `[i] `,不要直接使用 `arguments` | ||
- 严格来说用 `fn.apply(y, arguments)` 是没问题的,但除此之外都不行(例如 `.slice`)。 `Function#apply` 是特别的存在。 | ||
- 请注意,给函数添加属性值(例如 `fn.$inject = ...`)和绑定函数(即 `Function#bind` 的结果)会生成隐藏类,因此此时使用 `#apply` 不安全。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这一行需要帮忙看一看
TODO/Optimization-killers.md
Outdated
|
||
vhf is also working on a similar project that tries to list every killers in V8 Crankshaft Engine: [V8 Bailout Reasons](https://github.com/vhf/v8-bailout-reasons). | ||
vhf 也做了一个类似的项目,试图将 V8 引擎的性能杀手全部列出来:[V8 Bailout Reasons](https://github.com/vhf/v8-bailout-reasons)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
working on 正在做
TODO/Optimization-killers.md
Outdated
|
||
It is important to note that patterns that cause optimization bailouts affect the entire containing function. Code is optimized 1 function at a time, without knowledge of what other code is doing (unless that code is being inlined in the function that is being currently optimized). | ||
记住一些会导致整个函数无法被优化的情况是很重要的。JS 代码被优化时,将会逐个优化函数,在优化各个函数的时候不会关心其它的代码做了什么(除非那些代码在已经被优化的函数中)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
除非那些代码在已经被优化的函数中
除非那些代码被内联在即将优化的函数中。
TODO/Optimization-killers.md
Outdated
|
||
This guide will cover most patterns that cause the containing function go to "deoptimization hell". They will be subject to change and suggested work-arounds may become unnecessary when the optimizing compiler is updated to recognize more and more patterns. | ||
这篇文章涵盖了大多数会导致函数进入“反优化地狱”的情况。不过在未来,优化编译器进行更新后能够识别越来越多的情况时,下面给出的建议与各种变通方法可能也会变的不再必要或者需要修改。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“反优化地狱” 感觉很奇怪啊。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
坠入“无法被优化的深渊” 如何
TODO/Optimization-killers.md
Outdated
@@ -188,52 +186,52 @@ function tryCatch(fn, ctx, args) { | |||
} | |||
|
|||
var result = tryCatch(mightThrow, void 0, [1,2,3]); | |||
//Unambiguously tells whether the call threw | |||
//明确地爆出 try-catch 会抛出什么 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
爆出 => 报出?
TODO/Optimization-killers.md
Outdated
|
||
#### 3.1. Reassigning a defined parameter while also mentioning `arguments` in the body (in sloppy mode only). Typical example: | ||
#### 3.1. 在宽松模式中,对一个已经被定义,同时在函数体中被 `arguments` 引用的参数重新赋值。典型案例: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
宽松模式,好像一般都不这样讲,非严格模式?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯嗯,刚查了的确是这样。把不专业的个人习惯叫法带进来了。
TODO/Optimization-killers.md
Outdated
|
||
This is actually possible in sloppy mode: | ||
在宽松模式下可以这么做: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
宽松模式,同上。
TODO/Optimization-killers.md
Outdated
- Never use `arguments` directly without `.length` or `[i]` | ||
- STRICTLY `fn.apply(y, arguments)` is ok, nothing else is, e.g. `.slice`. `Function#apply` is special. | ||
- Be aware that adding properties to functions (e.g. fn.$inject =...) and bound functions (i.e. the result of `Function#bind`) generate hidden classes and, therefore, are not safe when using `#apply`. | ||
- `arguments[i]` **`i` 需要始终未 arguments 的合法整型索引,且不允许越界** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
始终未 => 始终为
TODO/Optimization-killers.md
Outdated
> * 校对者: | ||
|
||
# Optimization killers | ||
# 性能优化杀手 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议标题改为:V8 性能优化杀手。-- 虽然原文标题没有指明,译文最好能精确一点,不做标题党哈:(
TODO/Optimization-killers.md
Outdated
|
||
It is **important to note** that even if the construct is unreachable or not run, these constructs still cause a function to be unoptimizable. | ||
**请注意**,即使这些语句不会被执行或者不会被访问到,它仍然会导致整个函数不能被优化。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
即使这些语句不会被执行或者不会被访问到
即使这些语句不会被访问到或者不会被执行
TODO/Optimization-killers.md
Outdated
|
||
Just to be clear on the last point: the entire containing function is unavailable for optimization, when you do any of this: | ||
最后盘一下:如果你用了下面任何一种情况,整个函数将不能被优化: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最后盘一下
最后明确一下
两位校对请稍等,下午修改 |
@sqrthree 按照两位校对意见修改完毕,另标题更改为“V8 性能优化杀手” @aladdin-add @zhaochuanxing 万分感谢两位大佬的校对! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
已经 merge 啦~ 快快麻溜发布到掘金专栏然后给我发下链接,方便及时添加积分哟。 |
No description provided.