js-self-profiling icon indicating copy to clipboard operation
js-self-profiling copied to clipboard

What if function calls are optimized out?

Open tdresser opened this issue 6 years ago • 3 comments

I believe some JavaScript engines will optimize out function calls in some cases.

@rniwa I think mentioned this last TPAC.

How should we handle these cases?

tdresser avatar Sep 18 '18 20:09 tdresser

If a function has side effects, it won't be optimized out. Namely, if you were to add instrumentation, then the instrumentation itself would be a side-effect and completely change the way JS engines optimize the code.

It's like quantum mechanics. Your observation of the perf would change the perf.

rniwa avatar Sep 19 '18 07:09 rniwa

Thank Ryosuke.

If we specified that the UA is allowed to not report arbitrary stacks, could we then only instrument functions with existing side effects?

I don't have a good intuition for how useful such a sampling profiler would be, but it would presumably be a fair bit better than nothing. Do you have any intuition on how useful this would be?

tdresser avatar Sep 19 '18 13:09 tdresser

I think that we should permit this, lest we radically change the execution characteristics as @rniwa pointed out. I'll document in the spec draft that we should tolerate missing frames for optimization purposes.

Realistically, I don't believe that omitting functions without side-effects should be significantly impactful on the usefulness of the aggregated data. I can imagine the precision of the distribution of exclusive time / leaf stack frames will suffer (being the least likely to have side effects), but inclusive execution times will still be immensely useful in determining the performance characteristics of complex sites (e.g. finding which modules/complex routines are hot has been very valuable for us).

acomminos avatar Sep 19 '18 21:09 acomminos