ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript-Chrome的V8标记功能可反复优化,直到放弃

2019-10-28 21:34:25  阅读:327  来源: 互联网

标签:google-chrome optimization profiler v8 javascript


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

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

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处于这种状态?

提前致谢!

解决方法:

仔细观察一下踪迹,似乎detectSingleScale每次都是新的闭合.每次都通过OSR(在更换堆栈时)进行优化,因此不会缓存非OSR版本.

首次创建并运行闭包时,它会通过OSR进行优化,并将生成的代码放入缓存中.

下次再次创建闭包时,首先会发现找不到优化的代码消息-Factory :: NewFunctionFromSharedFunctionInfo [1]尝试查找非OSR版本(OSR ID设置为BailoutId :: None()),并且没有.找不到任何版本,因为唯一的优化版本是OSR版本.

然后,V8看到热循环并决定对OSR进行功能-这次,它在高速缓存中找到具有匹配OSR ID的已经优化的代码并使用它.

这是一个复制品来说明这一点

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运行此文件时,我得到:

$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] https://github.com/v8/v8-git-mirror/blob/master/src/factory.cc#L1396-L1397

标签:google-chrome,optimization,profiler,v8,javascript
来源: https://codeday.me/bug/20191028/1955426.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有