Javascript Profiler在Windows上的Chrome 79中:self-time包括什么?

huangapple go评论67阅读模式
英文:

Javascript Profiler in Chrome 79 for Windows: What does self-time include?

问题

在Chrome 79 for Windows中运行浏览器内的JavaScript:从类似的线程中,听起来自我时间仅包括在特定函数内运行内联代码的时间,并排除运行子函数所花费的时间。

但在实践中,我注意到我的应用中一些函数,这些函数进行了大量的子调用,似乎与其他类似大小的函数相比,具有异常的自我时间,而其他函数几乎没有子调用(即我正在比较两个相对类似操作和操作数量的函数)。这两个函数的自我时间可能相差10倍。

我在想自我时间是否包括为这些调用准备时间等等?

也许,这个具有子调用的函数的较高自我时间部分是由V8后续优化引起的,因此在分析器的采样时间内,我正在比较已经优化的函数的自我时间与尚未优化的函数的自我时间,后者在优化之前可能运行速度慢100倍。也许这是问题的原因?

英文:

Running in-browser Javascript in Chrome 79 for Windows :: From similar threads, it sounds like self-time includes only time to run the in-line code within a particular function, and excludes any time spent running sub functions.

But, in practice, I have noticed that some functions in my app that make a lot of sub-calls seem to have an inordinate amount of self-time compared to other similarly-sized functions with little or no sub-calls. (i.e. I'm comparing two functions with relatively similar operations, as well as number of ops). The self-time of these two functions can vary by 10x.

I'm wondering if self-time includes time to prepare for those calls, etc?

Perhaps, it's possible that some of that higher self-time of the function with sub-calls is due to later optimization by V8 and therefore during the sample time of the profiler, I'm comparing the self-time of an optimized function vs a not-yet-optimized function, which could run 100x slower prior to optimization. Maybe this is the culprit?

答案1

得分: 1

self-time includes only time to run the in-line code within a particular function, and excludes any time spent running sub functions
"self-time"仅包括在特定函数内运行内联代码的时间,不包括运行子函数所花费的时间。

Yes, "self time" is the number of tick samples that occurred in the given function.
是的,“self time”是在给定函数中发生的时钟采样数。

I'm wondering if self-time includes time to prepare for those calls, etc?
我想知道self-time是否包括为这些调用做准备的时间等?

"time to prepare calls" is not measured separately.
“为调用做准备的时间”没有单独测量。

I have noticed that some functions in my app that make a lot of sub-calls seem to have an inordinate amount of self-time
我注意到我的应用程序中有一些函数,它们进行了大量的子调用,似乎具有过多的self-time。

I would guess that what you're observing is caused by inlining. When a function gets optimized, and the compiler decides to inline one or more called functions, then the profiler afterwards can't possibly distinguish which instructions originally came from where (part of the reason why inlining can be beneficial is because it can allow elimination of redundancies, which naturally blurs the lines of which original function a given instruction "belongs to"). Does that make sense?

If you want to exclude the effects of inlining when profiling, you can turn off inlining. In Node/V8, you can run with --noturbo-inlining. (FWIW, in C/C++ this is true as well, where GCC/Clang understand -fno-inline.) Note that turning off inlining changes the performance characteristics of your app, so it can yield misleading results (specifically: it could be that without inlining you'll observe a performance issue that simply goes away when inlining is turned on); but it can also be helpful for pinpointing what is slow.
我猜你观察到的现象是由内联导致的。当函数被优化,并且编译器决定内联一个或多个被调用的函数时,后续的分析器无法区分哪些指令最初来自哪里(内联之所以有益的部分原因是它可以消除冗余,这自然地模糊了给定指令属于哪个原始函数的界限)。这有道理吗?

如果您想在分析时排除内联的影响,您可以关闭内联。在Node/V8中,您可以使用--noturbo-inlining运行。值得一提的是,在C/C++中也是如此,GCC/Clang理解-fno-inline。请注意,关闭内联会改变应用程序的性能特性,因此可能会产生误导性的结果(具体来说:如果没有内联,您可能会观察到一个性能问题,当打开内联时,它会自然消失);但它也有助于确定是什么导致了性能问题。

英文:

> self-time includes only time to run the in-line code within a particular function, and excludes any time spent running sub functions

Yes, "self time" is the number of tick samples that occurred in the given function.

> I'm wondering if self-time includes time to prepare for those calls, etc?

"time to prepare calls" is not measured separately.

> I have noticed that some functions in my app that make a lot of sub-calls seem to have an inordinate amount of self-time

I would guess that what you're observing is caused by inlining. When a function gets optimized, and the compiler decides to inline one or more called functions, then the profiler afterwards can't possibly distinguish which instructions originally came from where (part of the reason why inlining can be beneficial is because it can allow elimination of redundancies, which naturally blurs the lines of which original function a given instruction "belongs to"). Does that make sense?

If you want to exclude the effects of inlining when profiling, you can turn off inlining. In Node/V8, you can run with --noturbo-inlining. (FWIW, in C/C++ this is true as well, where GCC/Clang understand -fno-inline.) Note that turning off inlining changes the performance characteristics of your app, so it can yield misleading results (specifically: it could be that without inlining you'll observe a performance issue that simply goes away when inlining is turned on); but it can also be helpful for pinpointing what is slow.

huangapple
  • 本文由 发表于 2020年1月7日 00:01:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/59615233.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定