Skip to content
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

Merged
merged 2 commits into from
Jul 3, 2017
Merged

V8 性能优化杀手 #1828

merged 2 commits into from
Jul 3, 2017

Conversation

lsvih
Copy link
Member

@lsvih lsvih commented Jun 30, 2017

No description provided.

@lsvih
Copy link
Member Author

lsvih commented Jun 30, 2017

#1769

- `arguments[i]` **`i` 需要始终未 arguments 的合法整型索引,且不允许越界**
- 除了 `.length` `[i] `,不要直接使用 `arguments`
- 严格来说用 `fn.apply(y, arguments)` 是没问题的,但除此之外都不行(例如 `.slice`)。 `Function#apply` 是特别的存在。
- 请注意,给函数添加属性值(例如 `fn.$inject = ...`)和绑定函数(即 `Function#bind` 的结果)会生成隐藏类,因此此时使用 `#apply` 不安全。
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一行需要帮忙看一看

@linhe0x0 linhe0x0 mentioned this pull request Jun 30, 2017

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

working on 正在做


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 代码被优化时,将会逐个优化函数,在优化各个函数的时候不会关心其它的代码做了什么(除非那些代码在已经被优化的函数中)。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

除非那些代码在已经被优化的函数中

除非那些代码被内联在即将优化的函数中。


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.
这篇文章涵盖了大多数会导致函数进入“反优化地狱”的情况。不过在未来,优化编译器进行更新后能够识别越来越多的情况时,下面给出的建议与各种变通方法可能也会变的不再必要或者需要修改。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“反优化地狱” 感觉很奇怪啊。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

坠入“无法被优化的深渊” 如何

@@ -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 会抛出什么
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

爆出 => 报出?


#### 3.1. Reassigning a defined parameter while also mentioning `arguments` in the body (in sloppy mode only). Typical example:
#### 3.1. 在宽松模式中,对一个已经被定义,同时在函数体中被 `arguments` 引用的参数重新赋值。典型案例:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

宽松模式,好像一般都不这样讲,非严格模式?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯嗯,刚查了的确是这样。把不专业的个人习惯叫法带进来了。


This is actually possible in sloppy mode:
在宽松模式下可以这么做:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

宽松模式,同上。

- 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 的合法整型索引,且不允许越界**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

始终未 => 始终为

> * 校对者:

# Optimization killers
# 性能优化杀手
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议标题改为:V8 性能优化杀手。-- 虽然原文标题没有指明,译文最好能精确一点,不做标题党哈:(


It is **important to note** that even if the construct is unreachable or not run, these constructs still cause a function to be unoptimizable.
**请注意**,即使这些语句不会被执行或者不会被访问到,它仍然会导致整个函数不能被优化。
Copy link

@zhaochuanxing zhaochuanxing Jul 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

即使这些语句不会被执行或者不会被访问到

即使这些语句不会被访问到或者不会被执行


Just to be clear on the last point: the entire containing function is unavailable for optimization, when you do any of this:
最后盘一下:如果你用了下面任何一种情况,整个函数将不能被优化:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最后盘一下

最后明确一下

@lsvih
Copy link
Member Author

lsvih commented Jul 1, 2017

两位校对请稍等,下午修改

@lsvih lsvih changed the title 性能优化杀手 V8 性能优化杀手 Jul 1, 2017
@lsvih
Copy link
Member Author

lsvih commented Jul 1, 2017

@sqrthree 按照两位校对意见修改完毕,另标题更改为“V8 性能优化杀手”

@aladdin-add @zhaochuanxing 万分感谢两位大佬的校对!

Copy link
Member

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@linhe0x0 linhe0x0 merged commit 950a1e9 into xitu:master Jul 3, 2017
@linhe0x0
Copy link
Member

linhe0x0 commented Jul 3, 2017

已经 merge 啦~ 快快麻溜发布到掘金专栏然后给我发下链接,方便及时添加积分哟。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants