首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Chrome的V8标记函数一遍又一遍地优化直到放弃

Chrome的V8标记函数一遍又一遍地优化直到放弃
EN

Stack Overflow用户
提问于 2014-12-23 19:13:50
回答 2查看 820关注 0票数 3

我有一个detectSingleScale JavaScript函数,V8正在试图优化它,据我所知,它无法优化它。

当使用--trace_deopt --trace_opt --trace_opt_verbose --code_comments运行Chrome时,我看到有数百行日志行,如下所示:

代码语言:javascript
复制
6087 [found optimized code for 0x1a9b67169161 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> at OSR AST id 218]
6088 [didn't find optimized code in optimized code map for 0x145b5fa71bb1 <SharedFunctionInfo detectSingleScale>]
6089 [marking 0x1a9b6721ab91 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> for recompilation, reason: hot and stable, ICs with typeinfo: 140/144 (97%), generic ICs: 0/144 (0%)]
6090 [found optimized code for 0x1a9b6721ab91 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> at OSR AST id 218]
6091 [didn't find optimized code in optimized code map for 0x145b5fa71bb1 <SharedFunctionInfo detectSingleScale>]
6092 [marking 0x1a9b672c80f1 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> for recompilation, reason: hot and stable, ICs with typeinfo: 140/144 (97%), generic ICs: 0/144 (0%)]
6093 [found optimized code for 0x1a9b672c80f1 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> at OSR AST id 218]
6094 [didn't find optimized code in optimized code map for 0x145b5fa71bb1 <SharedFunctionInfo detectSingleScale>]
6095 [marking 0x1a9b67379db1 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> for recompilation, reason: hot and stable, ICs with typeinfo: 140/144 (97%), generic ICs: 0/144 (0%)]
  • V8标记用于优化的detectSingleScale函数。
  • 然后它说它找到了优化的版本。
  • 但是它说没有找到它。整个过程一次又一次地重新开始。

优化代码的地址都不同。我想知道是什么会触发这样的V8行为。在什么情况下,一个函数可以将V8置于这样的状态?

提前感谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-12-24 08:59:15

从跟踪来看,每次detectSingleScale似乎都是一个新的闭包。每次都通过OSR (on堆栈替换)对其进行优化,因此它没有缓存的非OSR版本。

第一次创建和运行闭包时,通过OSR对其进行优化,并将其放入缓存中。

下次再次创建闭包时,首先得到didn't find optimized code消息-- Factory::NewFunctionFromSharedFunctionInfo1尝试查找-OSR版本(OSR id设置为BailoutId::None()),但找不到,因为唯一优化的版本是OSR。

然后V8看到热循环,并决定使用OSR函数--这一次它已经在缓存中找到具有匹配OSR id的优化代码并使用它。

这里有一个例子来说明这一点

代码语言:javascript
复制
function foo() {
  print('! creating bar')
  var bar = function () {
    for (var i = 0; i < 100000; i++) {
      // OSR happens in this loop.
    }

    // Add a literal here to ensure we hit Runtime_NewClosure
    // instead of FastNewClosureStub - stub doesn't log anything.
    var a = [];
  }

  print('! running bar')
  bar();
  print('-- done')
}

foo();
foo();
foo();

当我使用d8运行这个文件时,我得到:

代码语言:javascript
复制
$ out/ia32.release/d8 --trace-opt test.js
! creating bar
! running bar
[marking 0x4301b705 <JS Function bar (SharedFunctionInfo 0x4c208765)> for recompilation, reason: small function, ICs with typeinfo: 2/2 (100%), generic ICs: 0/2 (0%)]
[compiling method 0x4301b705 <JS Function bar (SharedFunctionInfo 0x4c208765)> using Crankshaft]
[optimizing 0x4301b705 <JS Function bar (SharedFunctionInfo 0x4c208765)> - took 0.082, 0.119, 0.047 ms]
-- done
! creating bar
[didn't find optimized code in optimized code map for 0x4c208765 <SharedFunctionInfo bar>]
! running bar
[marking 0x4301bdb5 <JS Function bar (SharedFunctionInfo 0x4c208765)> for recompilation, reason: small function, ICs with typeinfo: 2/2 (100%), generic ICs: 0/2 (0%)]
[found optimized code for 0x4301bdb5 <JS Function bar (SharedFunctionInfo 0x4c208765)> at OSR AST id 10]
-- done
! creating bar
[didn't find optimized code in optimized code map for 0x4c208765 <SharedFunctionInfo bar>]
! running bar
[marking 0x4301be35 <JS Function bar (SharedFunctionInfo 0x4c208765)> for recompilation, reason: hot and stable, ICs with typeinfo: 2/2 (100%), generic ICs: 0/2 (0%)]
[found optimized code for 0x4301be35 <JS Function bar (SharedFunctionInfo 0x4c208765)> at OSR AST id 10]
-- done

1

票数 4
EN

Stack Overflow用户

发布于 2016-11-27 09:54:00

V8团队目前正在优化这个案例:铬问题追踪器

您可以使用--mark_shared_functions_for_tier_up来使用正在进行的工作。然后对detectSingleScale进行优化。

消息didn't find optimized code in optimized code map for不是很有用,最近从代码库中删除了它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27626588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档